simplify umask code

in a similar way as the remote_path code was implemented:
just patch the RemoteRepository class object
This commit is contained in:
Thomas Waldmann 2015-08-04 12:31:06 +02:00
parent 741715cd0e
commit 175a6d7b04
3 changed files with 6 additions and 14 deletions

View file

@ -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, \
get_cache_dir, get_keys_dir, format_timedelta, prune_within, prune_split, \
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
@ -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'])
self.verbose = args.verbose
set_umask(args.umask)
os.umask(args.umask)
RemoteRepository.remote_path = args.remote_path
RemoteRepository.umask = args.umask
update_excludes(args)
return args.func(args)

View file

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

View file

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