diff --git a/lib/backend.py b/lib/backend.py index a3c3fa16f5f617e95082f1bd492af5b26714f7d6..fb1ed0c7add193cfcc82fc5ea714ce96100e4d0d 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -2576,7 +2576,10 @@ def JobQueueRename(old, new): _EnsureJobQueueFile(old) _EnsureJobQueueFile(new) - utils.RenameFile(old, new, mkdir=True) + getents = runtime.GetEnts() + + utils.RenameFile(old, new, mkdir=True, mkdir_mode=0700, + dir_uid=getents.masterd_uid, dir_gid=getents.masterd_gid) def BlockdevClose(instance_name, disks): diff --git a/lib/utils/io.py b/lib/utils/io.py index 08c99908b656c9d872ddd856a14cd29d397993cb..8ed204ccfe5f93aabaf7c80dccbb89c22159fa89 100644 --- a/lib/utils/io.py +++ b/lib/utils/io.py @@ -290,7 +290,8 @@ def RemoveDir(dirname): raise -def RenameFile(old, new, mkdir=False, mkdir_mode=0750): +def RenameFile(old, new, mkdir=False, mkdir_mode=0750, dir_uid=None, + dir_gid=None): """Renames a file. @type old: string @@ -301,6 +302,10 @@ def RenameFile(old, new, mkdir=False, mkdir_mode=0750): @param mkdir: Whether to create target directory if it doesn't exist @type mkdir_mode: int @param mkdir_mode: Mode for newly created directories + @type dir_uid: int + @param dir_uid: The uid for the (if fresh created) dir + @type dir_gid: int + @param dir_gid: The gid for the (if fresh created) dir """ try: @@ -311,7 +316,10 @@ def RenameFile(old, new, mkdir=False, mkdir_mode=0750): # as efficient. if mkdir and err.errno == errno.ENOENT: # Create directory and try again - Makedirs(os.path.dirname(new), mode=mkdir_mode) + dir_path = os.path.dirname(new) + Makedirs(dir_path, mode=mkdir_mode) + if not (dir_uid is None or dir_gid is None): + os.chown(dir_path, dir_uid, dir_gid) return os.rename(old, new)