From 56664461ae794acee098f85d8c33b438909952f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wei-Yin=20Chen=20=28=E9=99=B3=E5=A8=81=E5=B0=B9=29?= Date: Tue, 23 May 2017 18:37:23 -0700 Subject: [PATCH] Support btrfs snapshot in gclient-new-workdir.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the repo is a btrfs subvolume, take a snapshot instead of using "cp --reflink". Taking a snapshot is much faster, and uses less disk space for metadata. Bug: 721585 Change-Id: I97753dc30d46ff56d84d65f8d815c19d09cf104b Reviewed-on: https://chromium-review.googlesource.com/513586 Reviewed-by: Robbie Iannucci Commit-Queue: Wei-Yin Chen (陳威尹) --- gclient-new-workdir.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/gclient-new-workdir.py b/gclient-new-workdir.py index eef5c329f..4eab72f97 100755 --- a/gclient-new-workdir.py +++ b/gclient-new-workdir.py @@ -60,18 +60,30 @@ def support_cow(src, dest): return True +def try_vol_snapshot(src, dest): + try: + subprocess.check_call(['btrfs', 'subvol', 'snapshot', src, dest], + stderr=subprocess.STDOUT) + except subprocess.CalledProcessError: + return False + return True + + def main(): args = parse_options() gclient = os.path.join(args.repository, '.gclient') new_gclient = os.path.join(args.new_workdir, '.gclient') - os.makedirs(args.new_workdir) - if args.reflink is None: - args.reflink = support_cow(gclient, new_gclient) - if args.reflink: - print('Copy-on-write support is detected.') - os.symlink(gclient, new_gclient) + if try_vol_snapshot(args.repository, args.new_workdir): + args.reflink = True + else: + os.makedirs(args.new_workdir) + if args.reflink is None: + args.reflink = support_cow(gclient, new_gclient) + if args.reflink: + print('Copy-on-write support is detected.') + os.symlink(gclient, new_gclient) for root, dirs, _ in os.walk(args.repository): if '.git' in dirs: