[PATCH] Unison with eCryptfs
Irányossy Knoblauch Artúr <[email protected]>
| Newsgroups | gmane.network.unison.devel |
|---|---|
| Message-ID | <CAJCedbjbHkYCp34+z7ywZ+yzG724noQCfWVwOXm2Xr5yj_Z3FA@mail.gmail.com> |
Hi Everyone! Currently Unison will fail to sync files with more than 64 character long file names on systems using eCryptfs. Unison still has some trouble creating proper temporary file names on certain file systems which has some limitations on the maximum allowed file name length: for example, eCryptfs has a limitation of 143 characters long file names [1]. eCryptfs is widely used: for example the default Ubuntu installer offers you to encrypt your home folder using eCryptfs. If someone wants to use Unison on a system using encrypted home folders, Unison will highly likely fail to create temporary files. You can find users complaining about this in various places over the Internet ([2] [3] [4] [5]). A very similar problem related to temporary file name lengths was fixed in the past (where Unison tried to create temporary files with more than 256 characters long names). The approach was to crop file names to 64 characters and add an MD5 digest of the original file name to the temporary name. Using this method, if you have a file with 65 'a' characters Unison will fail to create a 148 characters long temporary file: .unison.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac743a45e0d2e6a95cb859adae0248435.0e30133d04f8d05f6556aa7ddc20ef74.unison.tmp I have created a patch that fixes this problem by ensuring that all temporary file names will be limited to exactly 143 characters. (The limit can be easily and safely modified). Please review it. Thank you very much, and have a nice day! ;-) References: [1] eCryptfs maximum file length: https://bugs.launchpad.net/ecryptfs/+bug/344878 [2] Unison fails to synchronize some git repositories: http://superuser.com/questions/629558/unison-fails-to-synchronize-some-git-repositories [3] Has Unison error on “File name too long”: http://askubuntu.com/questions/232322/has-unison-error-on-file-name-too-long [4] File name too long (ecryptfs): http://groups.yahoo.com/neo/groups/unison-users/conversations/messages/10756 [5] long file names: http://groups.yahoo.com/neo/groups/unison-users/conversations/messages/10880 _______________________________________________ Unison-hackers mailing list [email protected] http://lists.seas.upenn.edu/mailman/listinfo/unison-hackers
limit_temp_file_names_to_be_compatible_with_eCryptfs.patch
(text/x-patch, 1.5 KB)
--- os.ml.orig 2013-10-24 12:41:54.000000000 +0200
+++ os.ml 2013-10-24 13:27:27.000000000 +0200
@@ -322,18 +322,32 @@
let s =
if i=0 then suffix
else Printf.sprintf "..%03d.%s" i suffix in
+
+ (* Do not use longer temp-file names than the file system permits.
+ * eCryptfs has the lowest file name length limit I know of: 143 bytes.
+ *)
+
+
+
let tempPath =
match Path.deconstructRev path with
None ->
assert false
| Some (name, parentPath) ->
let name = Name.toString name in
- let len = String.length name in
- let maxlen = 64 in
+ let nameLen = String.length name in
+ let maxFileNameLength = 143 in (* eCryptfs limit *)
+ let prefixLen = String.length prefix in
+ let suffixLen = String.length s in
+ let maxLen = maxFileNameLength - prefixLen - suffixLen in
+
let name =
- if len <= maxlen then name else
- (truncate_filename name maxlen ^
- Digest.to_hex (Digest.string name))
+ if nameLen <= maxLen then name else
+ let nameDigest = Digest.to_hex (Digest.string name) in
+ let nameDigestLen = String.length nameDigest in
+ let maxLen = maxLen - nameDigestLen in
+ assert(maxLen>0);
+ (truncate_filename name maxLen ^ nameDigest)
in
Path.child parentPath (Name.fromString (prefix ^ name ^ s))
in