chiark / gitweb /
make common.local_rsync() method for pre-configured local rsyncs
authorHans-Christoph Steiner <hans@eds.org>
Mon, 20 Nov 2017 14:54:00 +0000 (15:54 +0100)
committerHans-Christoph Steiner <hans@eds.org>
Wed, 22 Nov 2017 10:40:16 +0000 (11:40 +0100)
fdroidserver/common.py
fdroidserver/server.py

index c1b89d82f3673dc501a696278466c8954af80fb1..98bc2cb2aacd8e3601b9aba2d146768bfa2fcab8 100644 (file)
@@ -2717,6 +2717,28 @@ def string_is_integer(string):
         return False
 
 
+def local_rsync(options, fromdir, todir):
+    '''Rsync method for local to local copying of things
+
+    This is an rsync wrapper with all the settings for safe use within
+    the various fdroidserver use cases. This uses stricter rsync
+    checking on all files since people using offline mode are already
+    prioritizing security above ease and speed.
+
+    '''
+    rsyncargs = ['rsync', '--recursive', '--safe-links', '--times', '--perms',
+                 '--one-file-system', '--delete', '--chmod=Da+rx,Fa-x,a+r,u+w']
+    if not options.no_checksum:
+        rsyncargs.append('--checksum')
+    if options.verbose:
+        rsyncargs += ['--verbose']
+    if options.quiet:
+        rsyncargs += ['--quiet']
+    logging.debug(' '.join(rsyncargs + [fromdir, todir]))
+    if subprocess.call(rsyncargs + [fromdir, todir]) != 0:
+        raise FDroidException()
+
+
 def get_per_app_repos():
     '''per-app repos are dirs named with the packageName of a single app'''
 
index 013f155fc4dda24ac6b39f6363e2f3885088120e..116c27f8f1a55a788be65b5a4acb996befb8286c 100644 (file)
@@ -262,22 +262,6 @@ def update_serverwebroot(serverwebroot, repo_section):
                 raise FDroidException()
 
 
-def _local_sync(fromdir, todir):
-    rsyncargs = ['rsync', '--recursive', '--safe-links', '--times', '--perms',
-                 '--one-file-system', '--delete', '--chmod=Da+rx,Fa-x,a+r,u+w']
-    # use stricter rsync checking on all files since people using offline mode
-    # are already prioritizing security above ease and speed
-    if not options.no_checksum:
-        rsyncargs.append('--checksum')
-    if options.verbose:
-        rsyncargs += ['--verbose']
-    if options.quiet:
-        rsyncargs += ['--quiet']
-    logging.debug(' '.join(rsyncargs + [fromdir, todir]))
-    if subprocess.call(rsyncargs + [fromdir, todir]) != 0:
-        raise FDroidException()
-
-
 def sync_from_localcopy(repo_section, local_copy_dir):
     '''Syncs the repo from "local copy dir" filesystem to this box
 
@@ -290,8 +274,9 @@ def sync_from_localcopy(repo_section, local_copy_dir):
     logging.info('Syncing from local_copy_dir to this repo.')
     # trailing slashes have a meaning in rsync which is not needed here, so
     # make sure both paths have exactly one trailing slash
-    _local_sync(os.path.join(local_copy_dir, repo_section).rstrip('/') + '/',
-                repo_section.rstrip('/') + '/')
+    common.local_rsync(options,
+                       os.path.join(local_copy_dir, repo_section).rstrip('/') + '/',
+                       repo_section.rstrip('/') + '/')
 
     offline_copy = os.path.join(local_copy_dir, BINARY_TRANSPARENCY_DIR)
     if os.path.exists(os.path.join(offline_copy, '.git')):
@@ -308,7 +293,7 @@ def update_localcopy(repo_section, local_copy_dir):
 
     '''
     # local_copy_dir is guaranteed to have a trailing slash in main() below
-    _local_sync(repo_section, local_copy_dir)
+    common.local_rsync(options, repo_section, local_copy_dir)
 
     offline_copy = os.path.join(os.getcwd(), BINARY_TRANSPARENCY_DIR)
     if os.path.isdir(os.path.join(offline_copy, '.git')):
@@ -357,7 +342,9 @@ def update_servergitmirrors(servergitmirrors, repo_section):
             shutil.rmtree(dotgit)
 
         # rsync is very particular about trailing slashes
-        _local_sync(repo_section.rstrip('/') + '/', git_repodir.rstrip('/') + '/')
+        common.local_rsync(options,
+                           repo_section.rstrip('/') + '/',
+                           git_repodir.rstrip('/') + '/')
 
         # use custom SSH command if identity_file specified
         ssh_cmd = 'ssh -oBatchMode=yes'