aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2017-03-21 23:34:18 +0100
committerLaurent Bachelier <laurent@bachelier.name>2017-03-21 23:35:24 +0100
commit2c2e6a832a2682dc924c79a3056b6ccb35714f8b (patch)
treeb19aa1247b477d47ae4bf5039cd5dba815648d8d
parentRelease 1.1.1 (diff)
downloadbrutha-2c2e6a832a2682dc924c79a3056b6ccb35714f8b.tar.xz
Add options to ignore symbolic links; ignore both kinds by default
-rw-r--r--README6
-rw-r--r--brutha/__main__.py7
-rw-r--r--brutha/tree.py19
3 files changed, 30 insertions, 2 deletions
diff --git a/README b/README
index c2a12a1..463826e 100644
--- a/README
+++ b/README
@@ -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)