Skip to content

Commit

Permalink
Move spawnEditPermissions to the EditPermissionsModal
Browse files Browse the repository at this point in the history
  • Loading branch information
jelly authored and martinpitt committed Apr 24, 2024
1 parent 17ef0ce commit 20ee527
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 43 deletions.
39 changes: 0 additions & 39 deletions src/apis/spawnHelpers.jsx

This file was deleted.

24 changes: 20 additions & 4 deletions src/fileActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ import {
etc_passwd_syntax as etcPasswdSyntax
} from "pam_user_parser.js";
import { FileAutoComplete } from "../pkg/lib/cockpit-components-file-autocomplete";
import {
spawnEditPermissions,
} from "./apis/spawnHelpers";
import { map_permissions, inode_types } from "./common";

const _ = cockpit.gettext;
Expand Down Expand Up @@ -388,6 +385,25 @@ const EditPermissionsModal = ({ selected, path }) => {
}
};

const spawnEditPermissions = async () => {
const permissionChanged = mode !== selected.mode;
const ownerChanged = owner !== selected.user || group !== selected.group;

try {
if (permissionChanged)
await cockpit.spawn(["chmod", mode.toString(8), path.join("/") + "/" + selected.name],
{ superuser: "try", err: "message" });

if (ownerChanged)
await cockpit.spawn(["chown", owner + ":" + group, path.join("/") + "/" + selected.name],
{ superuser: "try", err: "message" });

Dialogs.close();
} catch (err) {
setErrorMessage(err.message);
}
};

function permissions_options() {
return [
...map_permissions((value, label) => (
Expand All @@ -413,7 +429,7 @@ const EditPermissionsModal = ({ selected, path }) => {
<>
<Button
variant="primary"
onClick={() => spawnEditPermissions(mode, path, selected, owner, group, Dialogs, setErrorMessage)}
onClick={() => spawnEditPermissions()}
>
{_("Change")}
</Button>
Expand Down

0 comments on commit 20ee527

Please sign in to comment.