Skip to content

Commit

Permalink
add cleanup in case chown fails
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasmatus committed Jan 3, 2025
1 parent e5c843a commit 5323e45
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/dialogs/copyPasteOwnership.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,30 @@ async function pasteAsOwner(clipboard: ClipboardInfo, dstPath: string, owner: st
await cockpit.spawn([
"cp",
"--recursive",
...clipboard.files.map(file => clipboard.path + file.name),
...clipboard.files.map(file => clipboard.path + "/" + file.name),
dstPath
], { superuser: "try" });

await cockpit.spawn([
"chown",
"--recursive",
owner,
...clipboard.files.map(file => dstPath + file.name),
...clipboard.files.map(file => dstPath + "/" + file.name),
], { superuser: "try" });
} catch (err) {
const e = err as cockpit.BasicError;
addAlert(e.message, AlertVariant.danger, `${new Date().getTime()}`);

// cleanup potentially copied files in case of "chown" fail
try {
await cockpit.spawn([
"rm",
"-rf",
...clipboard.files.map(file => dstPath + "/" + file.name)
], { superuser: "try" });
} catch (ex) {
console.warn(`Failed to clean up copied files in ${dstPath}`, ex);
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions test/check-application
Original file line number Diff line number Diff line change
Expand Up @@ -1957,8 +1957,6 @@ class TestFiles(testlib.MachineCase):
# Copy/paste file
m.execute("runuser -u admin mkdir /home/admin/newdir")
m.write('/home/admin/newfile', 'test_text\n', owner='admin:admin')
# "hack" test is too quick and UI doesnt reflect the chown done in m.write so it still
# thinks that file owner is root
b.wait_in_text("[data-item='newfile'] .item-owner", "admin")
b.click("[data-item='newfile']")
b.click("#dropdown-menu")
Expand Down

0 comments on commit 5323e45

Please sign in to comment.