Jelajahi Sumber

simplify umask code

in a similar way as the remote_path code was implemented:
just patch the RemoteRepository class object
Thomas Waldmann 9 tahun lalu
induk
melakukan
175a6d7b04
3 mengubah file dengan 6 tambahan dan 14 penghapusan
  1. 3 2
      borg/archiver.py
  2. 0 10
      borg/helpers.py
  3. 3 2
      borg/remote.py

+ 3 - 2
borg/archiver.py

@@ -21,7 +21,7 @@ from .helpers import Error, location_validator, format_time, format_file_size, \
     format_file_mode, ExcludePattern, exclude_path, adjust_patterns, to_localtime, timestamp, \
     format_file_mode, ExcludePattern, exclude_path, adjust_patterns, to_localtime, timestamp, \
     get_cache_dir, get_keys_dir, format_timedelta, prune_within, prune_split, \
     get_cache_dir, get_keys_dir, format_timedelta, prune_within, prune_split, \
     Manifest, remove_surrogates, update_excludes, format_archive, check_extension_modules, Statistics, \
     Manifest, remove_surrogates, update_excludes, format_archive, check_extension_modules, Statistics, \
-    is_cachedir, bigint_to_int, ChunkerParams, set_umask
+    is_cachedir, bigint_to_int, ChunkerParams
 from .remote import RepositoryServer, RemoteRepository
 from .remote import RepositoryServer, RemoteRepository
 
 
 
 
@@ -824,8 +824,9 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
 
 
         args = parser.parse_args(args or ['-h'])
         args = parser.parse_args(args or ['-h'])
         self.verbose = args.verbose
         self.verbose = args.verbose
-        set_umask(args.umask)
+        os.umask(args.umask)
         RemoteRepository.remote_path = args.remote_path
         RemoteRepository.remote_path = args.remote_path
+        RemoteRepository.umask = args.umask
         update_excludes(args)
         update_excludes(args)
         return args.func(args)
         return args.func(args)
 
 

+ 0 - 10
borg/helpers.py

@@ -605,13 +605,3 @@ def int_to_bigint(value):
     if value.bit_length() > 63:
     if value.bit_length() > 63:
         return value.to_bytes((value.bit_length() + 9) // 8, 'little', signed=True)
         return value.to_bytes((value.bit_length() + 9) // 8, 'little', signed=True)
     return value
     return value
-
-
-def set_umask(umask):
-    return os.umask(umask)
-
-
-def get_umask():
-    umask = set_umask(0)
-    set_umask(umask)
-    return umask

+ 3 - 2
borg/remote.py

@@ -10,7 +10,7 @@ import traceback
 
 
 from . import __version__
 from . import __version__
 
 
-from .helpers import Error, IntegrityError, get_umask
+from .helpers import Error, IntegrityError
 from .repository import Repository
 from .repository import Repository
 
 
 BUFSIZE = 10 * 1024 * 1024
 BUFSIZE = 10 * 1024 * 1024
@@ -109,6 +109,7 @@ class RepositoryServer:
 class RemoteRepository:
 class RemoteRepository:
     extra_test_args = []
     extra_test_args = []
     remote_path = None
     remote_path = None
+    umask = None
 
 
     class RPCError(Exception):
     class RPCError(Exception):
         def __init__(self, name):
         def __init__(self, name):
@@ -125,7 +126,7 @@ class RemoteRepository:
         self.unpacker = msgpack.Unpacker(use_list=False)
         self.unpacker = msgpack.Unpacker(use_list=False)
         self.p = None
         self.p = None
         # use local umask also for the remote process
         # use local umask also for the remote process
-        umask = ['--umask', '%03o' % get_umask()]
+        umask = ['--umask', '%03o' % self.umask]
         if location.host == '__testsuite__':
         if location.host == '__testsuite__':
             args = [sys.executable, '-m', 'borg.archiver', 'serve'] + umask + self.extra_test_args
             args = [sys.executable, '-m', 'borg.archiver', 'serve'] + umask + self.extra_test_args
         else:
         else: