Browse Source

FileOperation: Don't preserve ownership when copying files

Tim Ledbetter 1 year ago
parent
commit
81f5b3e66d
1 changed files with 3 additions and 15 deletions
  1. 3 15
      Userland/Services/FileOperation/main.cpp

+ 3 - 15
Userland/Services/FileOperation/main.cpp

@@ -30,8 +30,6 @@ struct WorkItem {
     DeprecatedString destination;
     DeprecatedString destination;
     off_t size;
     off_t size;
     mode_t mode { 0 };
     mode_t mode { 0 };
-    uid_t uid { 0 };
-    gid_t gid { 0 };
 };
 };
 
 
 static void report_warning(StringView message);
 static void report_warning(StringView message);
@@ -91,8 +89,6 @@ static ErrorOr<int> collect_copy_work_items(DeprecatedString const& source, Depr
             .destination = LexicalPath::join(destination, LexicalPath::basename(source)).string(),
             .destination = LexicalPath::join(destination, LexicalPath::basename(source)).string(),
             .size = st.st_size,
             .size = st.st_size,
             .mode = st.st_mode,
             .mode = st.st_mode,
-            .uid = st.st_uid,
-            .gid = st.st_gid,
         });
         });
         return 0;
         return 0;
     }
     }
@@ -104,8 +100,6 @@ static ErrorOr<int> collect_copy_work_items(DeprecatedString const& source, Depr
         .destination = LexicalPath::join(destination, LexicalPath::basename(source)).string(),
         .destination = LexicalPath::join(destination, LexicalPath::basename(source)).string(),
         .size = 0,
         .size = 0,
         .mode = st.st_mode,
         .mode = st.st_mode,
-        .uid = st.st_uid,
-        .gid = st.st_gid,
     });
     });
 
 
     Core::DirIterator dt(source, Core::DirIterator::SkipParentAndBaseDir);
     Core::DirIterator dt(source, Core::DirIterator::SkipParentAndBaseDir);
@@ -142,8 +136,6 @@ static ErrorOr<int> collect_move_work_items(DeprecatedString const& source, Depr
             .destination = LexicalPath::join(destination, LexicalPath::basename(source)).string(),
             .destination = LexicalPath::join(destination, LexicalPath::basename(source)).string(),
             .size = st.st_size,
             .size = st.st_size,
             .mode = st.st_mode,
             .mode = st.st_mode,
-            .uid = st.st_uid,
-            .gid = st.st_gid,
         });
         });
         return 0;
         return 0;
     }
     }
@@ -155,8 +147,6 @@ static ErrorOr<int> collect_move_work_items(DeprecatedString const& source, Depr
         .destination = LexicalPath::join(destination, LexicalPath::basename(source)).string(),
         .destination = LexicalPath::join(destination, LexicalPath::basename(source)).string(),
         .size = 0,
         .size = 0,
         .mode = st.st_mode,
         .mode = st.st_mode,
-        .uid = st.st_uid,
-        .gid = st.st_gid,
     });
     });
 
 
     Core::DirIterator dt(source, Core::DirIterator::SkipParentAndBaseDir);
     Core::DirIterator dt(source, Core::DirIterator::SkipParentAndBaseDir);
@@ -245,11 +235,10 @@ ErrorOr<int> execute_work_items(Vector<WorkItem> const& items)
             outln("PROGRESS {} {} {} {} {} {} {}", i, items.size(), executed_work_bytes, total_work_bytes, item_done, item.size, item.source);
             outln("PROGRESS {} {} {} {} {} {} {}", i, items.size(), executed_work_bytes, total_work_bytes, item_done, item.size, item.source);
         };
         };
 
 
-        auto copy_file = [&](DeprecatedString const& source, DeprecatedString const& destination, mode_t mode, uid_t uid, gid_t gid) -> ErrorOr<int> {
+        auto copy_file = [&](DeprecatedString const& source, DeprecatedString const& destination, mode_t mode) -> ErrorOr<int> {
             auto source_file = TRY(Core::File::open(source, Core::File::OpenMode::Read));
             auto source_file = TRY(Core::File::open(source, Core::File::OpenMode::Read));
             // FIXME: When the file already exists, let the user choose the next action instead of renaming it by default.
             // FIXME: When the file already exists, let the user choose the next action instead of renaming it by default.
             auto destination_file = TRY(open_destination_file(destination, mode));
             auto destination_file = TRY(open_destination_file(destination, mode));
-            TRY(Core::System::fchown(destination_file->fd(), uid, gid));
             auto buffer = TRY(ByteBuffer::create_zeroed(64 * KiB));
             auto buffer = TRY(ByteBuffer::create_zeroed(64 * KiB));
 
 
             while (true) {
             while (true) {
@@ -285,7 +274,6 @@ ErrorOr<int> execute_work_items(Vector<WorkItem> const& items)
             if (maybe_error.is_error() && maybe_error.error().code() != EEXIST)
             if (maybe_error.is_error() && maybe_error.error().code() != EEXIST)
                 return Error::from_syscall("mkdir"sv, -errno);
                 return Error::from_syscall("mkdir"sv, -errno);
 
 
-            TRY(Core::System::chown(item.destination, item.uid, item.gid));
             break;
             break;
         }
         }
 
 
@@ -295,7 +283,7 @@ ErrorOr<int> execute_work_items(Vector<WorkItem> const& items)
         }
         }
 
 
         case WorkItem::Type::CopyFile: {
         case WorkItem::Type::CopyFile: {
-            TRY(copy_file(item.source, item.destination, item.mode, item.uid, item.gid));
+            TRY(copy_file(item.source, item.destination, item.mode));
             break;
             break;
         }
         }
 
 
@@ -323,7 +311,7 @@ ErrorOr<int> execute_work_items(Vector<WorkItem> const& items)
                 }
                 }
 
 
                 // EXDEV means we have to copy the file data and then remove the original
                 // EXDEV means we have to copy the file data and then remove the original
-                TRY(copy_file(item.source, item.destination, item.mode, item.uid, item.gid));
+                TRY(copy_file(item.source, item.destination, item.mode));
                 TRY(Core::System::unlink(item.source));
                 TRY(Core::System::unlink(item.source));
                 break;
                 break;
             }
             }