aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Files
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-11-22 18:36:31 -0600
committerGitHub <noreply@github.com>2025-11-22 18:36:31 -0600
commit47490e366b5bc4b2a1679fba50655697afbe7137 (patch)
treeae98bb4fb66d20e5fecd69267bcbb17d80c4986b /src/slskd/Files
parent2e073014a003fc4e972a9a2677fccd3d30074cd2 (diff)
parent6ba7311d48b95ca75f49b3b28c1a8db810f87fe1 (diff)
downloadslskd-47490e366b5bc4b2a1679fba50655697afbe7137.tar.gz
Merge branch 'master' into dependabot/npm_and_yarn/src/web/axios-0.30.2
Diffstat (limited to 'src/slskd/Files')
-rw-r--r--src/slskd/Files/FileService.cs19
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())
{