Skip to content

Commit

Permalink
Added UnixFileMode check on purge for files - need to add recursive c…
Browse files Browse the repository at this point in the history
…heck for directories and on empty
  • Loading branch information
jorystewart committed Sep 9, 2024
1 parent 2312950 commit c9c24c2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Trashman/src/Trash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ public static void EmptyTrashContents()
ConsoleKeyInfo confirmKey = Console.ReadKey(true);
if (confirmKey.Key == ConsoleKey.Y)
{
Console.WriteLine("Deleting...")
Console.WriteLine("Deleting...");
foreach (FileSystemInfo item in trashFilesDir.EnumerateFileSystemInfos())
{
switch (item)
Expand Down Expand Up @@ -906,6 +906,19 @@ where starReplace.IsMatch(item.Item2.Name)
{
try
{
UnixFileMode mode = File.GetUnixFileMode(trashFilesDir + "/" + item.Item2.Name);
if ((mode & UnixFileMode.UserWrite) != UnixFileMode.UserWrite)
{
try
{
File.SetUnixFileMode(trashFilesDir + "/" + item.Item2.Name, UnixFileMode.UserWrite);
}
catch
{
Console.WriteLine("File " + item.Item2.Name + " lacks the user write flag. Attempting to set it failed. Skipping...");
continue;
}
}
File.Delete(trashFilesDir + "/" + item.Item2.Name);
}
catch (Exception e) when (e is ArgumentException or ArgumentNullException)
Expand Down

0 comments on commit c9c24c2

Please sign in to comment.