From 92d8069f3a0c26f6c766dbe67f948eda80df2901 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sat, 16 Jul 2022 13:29:19 -0500 Subject: [PATCH] Implimented chmod, chown logic --- plugins/file_properties/plugin.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/plugins/file_properties/plugin.py b/plugins/file_properties/plugin.py index 72c74a1..9236370 100644 --- a/plugins/file_properties/plugin.py +++ b/plugins/file_properties/plugin.py @@ -1,5 +1,5 @@ # Python imports -import os, threading, subprocess, time +import os, threading, subprocess, time, pwd, grp from datetime import datetime # Gtk imports @@ -154,7 +154,27 @@ class Plugin(Manifest): print("\nNew chmod flags...") print(f"Old: {''.join(properties.chmod_stat)}") print(f"New: {chmod_stat}") - # self._guest_fs.chmod(int(chmod_stat), properties.file_uri) + + command = ["chmod", f"{chmod_stat}", properties.file_uri] + with subprocess.Popen(command, stdout=subprocess.PIPE) as proc: + result = proc.stdout.read().decode("UTF-8").strip() + print(result) + except Exception as e: + print(f"Couldn't chmod\nFile: {properties.file_uri}") + print( repr(e) ) + + + owner = self._file_owner.get_text() + group = self._file_group.get_text() + if owner is not properties.file_owner or group is not properties.file_group: + try: + print("\nNew owner/group flags...") + print(f"Old:\n\tOwner: {properties.file_owner}\n\tGroup: {properties.file_group}") + print(f"New:\n\tOwner: {owner}\n\tGroup: {group}") + + uid = pwd.getpwnam(owner).pw_uid + gid = grp.getgrnam(group).gr_gid + os.chown(properties.file_uri, uid, gid) except Exception as e: print(f"Couldn't chmod\nFile: {properties.file_uri}") print( repr(e) )