[PATCH] largefiles: adding a file of 2GB causes errors in dirstate (issue3063)

Na'Tosha Bard natosha at unity3d.com
Wed Jan 11 12:08:40 CST 2012


# HG changeset patch
# User Na'Tosha Bard <natosha at unity3d.com>
# Date 1326305303 -3600
# Node ID 6cbd00c7cee81db062e0a86d2ee63fb85fa9bab2
# Parent  c47d69ce5208d5b5cfd2fb2f0f1d7a2b4795fbf5
largefiles: adding a file of 2GB causes errors in dirstate (issue3063)

Due to limitations of Mercurial's native dirstate, files that are >= 2 GB
cannot be added.  Since it's not unlikely users of largefiles will try to
add very large files, this patch checks the file size and politely aborts
the add, telling the user only files under 2 GB are supported.

diff -r c47d69ce5208 -r 6cbd00c7cee8 hgext/largefiles/__init__.py
--- a/hgext/largefiles/__init__.py	Wed Jan 11 09:27:53 2012 -0600
+++ b/hgext/largefiles/__init__.py	Wed Jan 11 19:08:23 2012 +0100
@@ -84,6 +84,8 @@
 largefile. To add the first largefile to a repository, you must
 explicitly do so with the --large flag passed to the :hg:`add`
 command.
+
+Please note that only files under 2 GB are supported.
 '''
 
 from mercurial import commands
diff -r c47d69ce5208 -r 6cbd00c7cee8 hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py	Wed Jan 11 09:27:53 2012 -0600
+++ b/hgext/largefiles/overrides.py	Wed Jan 11 19:08:23 2012 +0100
@@ -20,6 +20,9 @@
 import lfutil
 import lfcommands
 
+# 2 GB in bytes -- the maximum file size we can support
+_maxsize2gb = 2147483648
+
 # -- Utility functions: commonly/repeatedly needed functionality ---------------
 
 def installnormalfilesmatchfn(manifest):
@@ -96,6 +99,15 @@
     # when standins are created and added to the repo.
     wlock = repo.wlock()
     try:
+        # First check all files against the max filesize limit.  Do this
+        # separately so we don't abort later and risk leaving the working
+        # copy in a dirty state.
+        for f in lfnames:
+            size = os.lstat(repo.wjoin(f)).st_size
+            if size >= _maxsize2gb:
+                error = _('not adding %s: file is too large') % f
+                hint = _('only files under 2 GB are supported')
+                raise util.Abort(error, hint=hint)
         if not opts.get('dry_run'):
             lfdirstate = lfutil.openlfdirstate(ui, repo)
             for f in lfnames:


More information about the Mercurial-devel mailing list