Ticket #906: Fix permissions on directories

ticket-769
Vadim vtroshchinskiy 2024-10-09 17:43:54 +02:00
parent fcbe1e9561
commit dea57835f3
1 changed files with 27 additions and 6 deletions

View File

@ -1007,7 +1007,7 @@ class OpengnsysGitLibrary:
stat_data = os.stat(full_path)
perms_json = json.dumps({
"file" : full_path_rel,
"path" : full_path_rel,
"mode" : stat_data.st_mode,
"uid" : stat_data.st_uid,
"gid" : stat_data.st_gid
@ -1079,7 +1079,6 @@ class OpengnsysGitLibrary:
while full_path_rel[0] == '/':
full_path_rel = full_path_rel[1:None]
if os.path.isdir(full_path) and subdir in self.rename_list and root != path:
self.logger.debug(f"Found directory to rename: {full_path}")
renamed_dir_path = full_path + "-opengnsys-renamed"
@ -1090,6 +1089,28 @@ class OpengnsysGitLibrary:
os.rename(full_path, renamed_dir_path)
if not ntfs and os.path.isdir(full_path) and not os.path.islink(full_path):
stat_data = os.stat(full_path)
perms_json = json.dumps({
"path" : full_path_rel,
"mode" : stat_data.st_mode,
"uid" : stat_data.st_uid,
"gid" : stat_data.st_gid
})
xattrs = str(xattr.get_all(full_path))
acls = posix1e.ACL(file=full_path)
xattrs_json = json.dumps({"file": full_path_rel, "xattrs" : xattrs})
# __getstate__ nos permite exportar el estado entero de la ACL
acl_data = str(base64.b64encode(acls.__getstate__()), 'utf-8')
acls_json = json.dumps({"file": full_path_rel, "acl" : acl_data })
perms_file.write(perms_json + "\n")
xattrs_file.write(xattrs_json + "\n")
acls_file.write(acls_json + "\n")
self.logger.debug("Finishing...")
@ -1219,15 +1240,15 @@ class OpengnsysGitLibrary:
perms_data = json.loads(line)
#self.logger.debug(f"Data: {acls_data}")
perms_file = perms_data['file']
perms_path = perms_data['path']
file_perms = perms_data['mode']
file_uid = perms_data['uid']
file_gid = perms_data['gid']
if perms_file.startswith("/"):
perms_file = perms_file[1:]
if perms_path.startswith("/"):
perms_path = perms_path[1:]
perms_file_path = os.path.join(path, perms_file)
perms_file_path = os.path.join(path, perms_path)
if os.path.exists(perms_file_path):
self.logger.debug(f"Applying permissions {file_perms}, owner {file_uid}, group {file_gid} to {perms_file_path}")