diff --git a/src/WasiConfiguration.cs b/src/WasiConfiguration.cs index 1f397f0..dc08dd0 100644 --- a/src/WasiConfiguration.cs +++ b/src/WasiConfiguration.cs @@ -7,40 +7,6 @@ namespace Wasmtime { - /// - /// The permissions granted for a directory when preopening it. - /// - [Flags] - public enum WasiDirectoryPermissions - { - /// - /// This directory can be read, for example its entries can be iterated. - /// - Read = 1, - - /// - /// This directory can be written to, for example new files can be created within it. - /// - Write = 2 - } - - /// - /// The permissions granted for files when preopening a directory. - /// - [Flags] - public enum WasiFilePermissions - { - /// - /// Files can be read. - /// - Read = 1, - - /// - /// Files can be written to. - /// - Write = 2 - } - /// /// Represents a WASI configuration. /// @@ -290,12 +256,10 @@ public WasiConfiguration WithInheritedStandardError() /// /// The path to the directory to add. /// The path the guest will use to open the directory. - /// The permissions that wasm will have to operate on . This can be used, for example, to provide readonly access to a directory. - /// The permissions that wasm will have for any file in this directory. + /// If true, operations that mutate the filesystem will be permitted under that path.If false, only + /// read operations will be permitted on under that path. /// Returns the current configuration. - public WasiConfiguration WithPreopenedDirectory( - string path, string guestPath, - WasiDirectoryPermissions directoryPermissions, WasiFilePermissions filePermissions) + public WasiConfiguration WithPreopenedDirectory(string path, string guestPath, bool mutable) { if (string.IsNullOrEmpty(path)) { @@ -306,7 +270,7 @@ public WasiConfiguration WithPreopenedDirectory( throw new ArgumentException("The guest path cannot be null or empty.", nameof(guestPath)); } - _preopenDirs.Add((path, guestPath, directoryPermissions, filePermissions)); + _preopenDirs.Add((path, guestPath, mutable)); return this; } @@ -444,7 +408,7 @@ private void SetPreopenDirectories(Handle config) { foreach (var dir in _preopenDirs) { - if (!Native.wasi_config_preopen_dir(config, dir.Path, dir.GuestPath, (nuint)dir.directoryPermissions, (nuint)dir.filePermissions)) + if (!Native.wasi_config_preopen_dir(config, dir.Path, dir.GuestPath, dir.Mutable)) { throw new InvalidOperationException($"Failed to preopen directory '{dir.Path}'."); } @@ -545,8 +509,7 @@ public static extern bool wasi_config_preopen_dir( Handle config, [MarshalAs(Extensions.LPUTF8Str)] string path, [MarshalAs(Extensions.LPUTF8Str)] string guestPath, - nuint dirPerms, - nuint filePerms + [MarshalAs(UnmanagedType.I1)] bool fs_mutable ); } @@ -555,7 +518,7 @@ nuint filePerms private string? _standardInputPath; private string? _standardOutputPath; private string? _standardErrorPath; - private readonly List<(string Path, string GuestPath, WasiDirectoryPermissions directoryPermissions, WasiFilePermissions filePermissions)> _preopenDirs = new List<(string, string, WasiDirectoryPermissions, WasiFilePermissions)>(); + private readonly List<(string Path, string GuestPath, bool Mutable)> _preopenDirs = new(); private bool _inheritArgs = false; private bool _inheritEnv = false; private bool _inheritStandardInput = false; diff --git a/tests/WasiTests.cs b/tests/WasiTests.cs index 70f1a45..4e8741c 100644 --- a/tests/WasiTests.cs +++ b/tests/WasiTests.cs @@ -287,7 +287,7 @@ public void ItSetsPreopenDirectories(string path) using var file = new TempFile(); var config = new WasiConfiguration() - .WithPreopenedDirectory(Path.GetDirectoryName(file.Path), "/foo", WasiDirectoryPermissions.Read | WasiDirectoryPermissions.Write, WasiFilePermissions.Read | WasiFilePermissions.Write); + .WithPreopenedDirectory(Path.GetDirectoryName(file.Path)!, "/foo", mutable:true); using var engine = new Engine(); using var module = Module.FromTextFile(engine, Path.Combine("Modules", path));