aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2016-03-15 22:35:50 +0100
committerLaurent Bachelier <laurent@bachelier.name>2016-03-15 22:36:42 +0100
commit5c10f7df7e4d76038db0dfb328afe52bb3f14c7a (patch)
tree894b7eff6237341d697d0cbf383221187c363ee7
parentConfigure flake8 (diff)
downloadbrutha-5c10f7df7e4d76038db0dfb328afe52bb3f14c7a.tar.xz
Add support for hardlinks and reflinks
-rw-r--r--brutha/__main__.py8
-rw-r--r--brutha/file.py8
-rw-r--r--brutha/tree.py3
3 files changed, 15 insertions, 4 deletions
diff --git a/brutha/__main__.py b/brutha/__main__.py
index 6097218..a279c53 100644
--- a/brutha/__main__.py
+++ b/brutha/__main__.py
@@ -4,8 +4,8 @@ from __future__ import absolute_import
import argparse
import sys
-from StringIO import StringIO
from multiprocessing import cpu_count
+from StringIO import StringIO
from .output import OUTPUTS
from .tree import Tree
@@ -40,6 +40,9 @@ def main():
help="Execute the script instead of printing it")
parser.add_argument('-j', '--jobs', type=int, default=cores,
help="Number of concurrent jobs")
+ 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")
parser.add_argument('src', help="Source directory", metavar='SOURCE')
parser.add_argument('dest', help="Destination directory", metavar='DESTINATION')
args = parser.parse_args()
@@ -48,7 +51,8 @@ def main():
tree = Tree(args.src, args.dest,
{'quality': args.quality, 'gain': args.gain, 'delete': args.delete,
'maxrate': args.maxrate, 'maxbits': args.maxbits,
- 'lossycheck': args.lossycheck},
+ 'lossycheck': args.lossycheck,
+ 'hardlink': args.hardlink, 'reflink': args.reflink},
log)
if args.execute:
stream = StringIO()
diff --git a/brutha/file.py b/brutha/file.py
index 0191cf1..1ccac12 100644
--- a/brutha/file.py
+++ b/brutha/file.py
@@ -116,9 +116,15 @@ class LossyFile(File):
return commands
def copy(self, commands):
+ if self.options['hardlink']:
+ option = ' -l'
+ elif self.options['reflink']:
+ option = ' --reflink=always'
+ else:
+ option = ''
if not self.sample_ok():
raise NotAllowed("Sample rate or bit depth too high")
- commands.append('cp %s %s' % (escape(self.src()), escape(self.dest())))
+ commands.append('cp%s %s %s' % (option, escape(self.src()), escape(self.dest())))
def sample_ok(self):
if not self.options['lossycheck']:
diff --git a/brutha/tree.py b/brutha/tree.py
index 848ba2c..e6968e8 100644
--- a/brutha/tree.py
+++ b/brutha/tree.py
@@ -14,7 +14,8 @@ class Tree(object):
self.path = path
self.destpath = destpath
self.options = {'quality': 8, 'gain': False, 'delete': False,
- 'maxrate': None, 'maxbits': None, 'lossycheck': True}
+ 'maxrate': None, 'maxbits': None, 'lossycheck': True,
+ 'hardlink': False, 'reflink': False}
if options:
self.options.update(options)
self.log = log