diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-10-20 09:08:56 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-10-20 09:08:56 -0500 |
| commit | 6bcc23c1856f9878509c940cc37b5d4fdb90e2d4 (patch) | |
| tree | 0574d0032b475f1e0204c724ecdc5f46fac11a55 /src/slskd/Files/FileService.cs | |
| parent | 75ad65dbed0333fd6bd0441a5599527c539366e0 (diff) | |
| parent | 0a15a71028c2a12795023550f28d416dd050763d (diff) | |
| download | slskd-6bcc23c1856f9878509c940cc37b5d4fdb90e2d4.tar.gz | |
Merge remote-tracking branch 'origin' into download-records
Diffstat (limited to 'src/slskd/Files/FileService.cs')
| -rw-r--r-- | src/slskd/Files/FileService.cs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/slskd/Files/FileService.cs b/src/slskd/Files/FileService.cs index a07bd051..e4adc7e7 100644 --- a/src/slskd/Files/FileService.cs +++ b/src/slskd/Files/FileService.cs @@ -379,6 +379,7 @@ namespace slskd.Files /// </remarks> /// <param name="sourceFilename">The fully qualified filename of the file to move.</param> /// <param name="destinationDirectory">The fully qualified directory to which to move the source file.</param> + /// <param name="unixFileMode">An optional Unix file mode to apply to the destination file.</param> /// <param name="overwrite">An optional value indicating whether the destination file should be overwritten if it already exists.</param> /// <param name="deleteSourceDirectoryIfEmptyAfterMove"> /// An optional value indicating whether the parent directory of the source file should be deleted if it is empty after the move. @@ -387,7 +388,7 @@ namespace slskd.Files /// <exception cref="ArgumentNullException">Thrown if either of the specified file or directories are null or contain only whitespace.</exception> /// <exception cref="FileNotFoundException">Thrown if the specified <paramref name="sourceFilename"/> does not exist.</exception> /// <exception cref="IOException">Thrown if the file can't be moved, or the <paramref name="deleteSourceDirectoryIfEmptyAfterMove"/> option is set and the operation fails.</exception> - public virtual string MoveFile(string sourceFilename, string destinationDirectory, bool overwrite = false, bool deleteSourceDirectoryIfEmptyAfterMove = false) + public virtual string MoveFile(string sourceFilename, string destinationDirectory, UnixFileMode? unixFileMode = null, bool overwrite = false, bool deleteSourceDirectoryIfEmptyAfterMove = false) { ArgumentNullException.ThrowIfNullOrWhiteSpace(sourceFilename, nameof(sourceFilename)); ArgumentNullException.ThrowIfNullOrWhiteSpace(destinationDirectory, nameof(destinationDirectory)); @@ -425,6 +426,22 @@ namespace slskd.Files Log.Debug("Successfully moved {Source} to {Destination}", sourceFilename, destinationFilename); + // attempting to use UnixCreateMode on Windows raises an Exception + // we *MUST* check the OS and skip this on Windows + if (!OperatingSystem.IsWindows()) + { + var appOption = OptionsMonitor.CurrentValue.Permissions.File.Mode; + var mode = unixFileMode ?? appOption?.ToUnixFileMode(); + + // if options haven't been passed in and none have been set in app config, omit this + // so that the application's umask will be applied, saving users the hassle of setting it twice. + if (mode.HasValue) + { + File.SetUnixFileMode(destinationFilename, mode.Value); + Log.Debug("Successfully set Unix file mode to {Mode}", mode); + } + } + // if the parent directory is empty after the move, delete it if (deleteSourceDirectoryIfEmptyAfterMove && !Directory.EnumerateFileSystemEntries(Path.GetDirectoryName(sourceFilename)).Any()) { |
