diff options
author | Laurent Bachelier <laurent@bachelier.name> | 2017-03-21 23:34:18 +0100 |
---|---|---|
committer | Laurent Bachelier <laurent@bachelier.name> | 2017-03-21 23:35:24 +0100 |
commit | 2c2e6a832a2682dc924c79a3056b6ccb35714f8b (patch) | |
tree | b19aa1247b477d47ae4bf5039cd5dba815648d8d | |
parent | Release 1.1.1 (diff) | |
download | brutha-2c2e6a832a2682dc924c79a3056b6ccb35714f8b.tar.xz |
Add options to ignore symbolic links; ignore both kinds by default
-rw-r--r-- | README | 6 | ||||
-rw-r--r-- | brutha/__main__.py | 7 | ||||
-rw-r--r-- | brutha/tree.py | 19 |
3 files changed, 30 insertions, 2 deletions
@@ -102,6 +102,12 @@ Recommendations Since encoding eats a lot of CPU, you should start it at a low priority. The simplest way is to run ``nice -n19 brutha`` instead of only ``brutha``. +Symbolic links +~~~~~~~~~~~~~~ +brutha ignores symbolic links by default, but can follow links outside of the +source path, or inside the source path, using options ``--outside`` and ``--inside``. + +This is modelled after mpd's ``follow_outside_symlinks`` and ``follow_inside_symlinks`` options. Changes ------- diff --git a/brutha/__main__.py b/brutha/__main__.py index a279c53..b839a59 100644 --- a/brutha/__main__.py +++ b/brutha/__main__.py @@ -40,6 +40,10 @@ def main(): help="Execute the script instead of printing it") parser.add_argument('-j', '--jobs', type=int, default=cores, help="Number of concurrent jobs") + parser.add_argument('-O', '--outside', action='store_true', + help="Follow directory symbolic links outside of the source directory") + parser.add_argument('-I', '--inside', action='store_true', + help="Follow directory symbolic links inside of the source directory") group = parser.add_mutually_exclusive_group() group.add_argument('-l', '--hardlink', action='store_true', help="Use hardlinks instead of a copy") group.add_argument('-r', '--reflink', action='store_true', help="Use reflinks instead of a copy") @@ -52,7 +56,8 @@ def main(): {'quality': args.quality, 'gain': args.gain, 'delete': args.delete, 'maxrate': args.maxrate, 'maxbits': args.maxbits, 'lossycheck': args.lossycheck, - 'hardlink': args.hardlink, 'reflink': args.reflink}, + 'hardlink': args.hardlink, 'reflink': args.reflink, + 'inside': args.inside, 'outside': args.outside}, log) if args.execute: stream = StringIO() diff --git a/brutha/tree.py b/brutha/tree.py index e6968e8..db4e4fc 100644 --- a/brutha/tree.py +++ b/brutha/tree.py @@ -15,11 +15,26 @@ class Tree(object): self.destpath = destpath self.options = {'quality': 8, 'gain': False, 'delete': False, 'maxrate': None, 'maxbits': None, 'lossycheck': True, - 'hardlink': False, 'reflink': False} + 'hardlink': False, 'reflink': False, + 'outside': False, 'inside': False} if options: self.options.update(options) self.log = log + def allowed(self, root, dirname): + path = os.path.join(root, dirname) + if not os.path.islink(path): + return True + + dest = os.path.join(root, os.readlink(path)) + outside = os.path.relpath(dest, self.path).startswith(os.path.pardir + os.path.sep) + if outside and self.options['outside']: + return True + elif not outside and self.options['inside']: + return True + else: + return False + def commands(self): commands = [] wanted = [] @@ -27,6 +42,8 @@ class Tree(object): if self.log: print >>self.log, "Walking source directory..." for root, dirs, files in os.walk(self.path, followlinks=True): + for dirname in [dirname for dirname in dirs if not self.allowed(root, dirname)]: + dirs.remove(dirname) num += 1 if not num % 200: self.progress(num) |