diff options
author | Joey Hess <joey@kitenet.net> | 2013-07-30 17:49:11 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-07-30 19:18:29 -0400 |
commit | fe0dcd5a298984d6cc8a5a28d7257a48acb58595 (patch) | |
tree | 899225013beb7d1d1be79c88aa6bbdad5ced8dc3 /Command/AddUrl.hs | |
parent | 1bb47eb93f81be71a0d1e4d67486de6ec651eb69 (diff) |
Fix a few bugs involving filenames that are at or near the filesystem's maximum filename length limit.
Started with a problem when running addurl on a really long url,
because the whole url is munged into the filename. Ended up doing
a fairly extensive review for places where filenames could get too large,
although it's hard to say I'm not missed any..
Backend.Url had a 128 character limit, which is fine when the limit is 255,
but not if it's a lot shorter on some systems. So check the pathconf()
limit. Note that this could result in fromUrl creating different keys
for the same url, if run on systems with different limits. I don't see
this is likely to cause any problems. That can already happen when using
addurl --fast, or if the content of an url changes.
Both Command.AddUrl and Backend.Url assumed that urls don't contain a
lot of multi-byte unicode, and would fail to truncate an url that did
properly.
A few places use a filename as the template to make a temp file.
While that's nice in that the temp file name can be easily related back to
the original filename, it could lead to `git annex add` failing to add a
filename that was at or close to the maximum length.
Note that in Command.Add.lockdown, the template is still derived from the
filename, just with enough space left to turn it into a temp file.
This is an important optimisation, because the assistant may lock down
a bunch of files all at once, and using the same template for all of them
would cause openTempFile to iterate through the same set of names,
looking for an unused temp file. I'm not very happy with the relatedTemplate
hack, but it avoids that slowdown.
Backend.WORM does not limit the filename stored in the key.
I have not tried to change that; so git annex add will fail on really long
filenames when using the WORM backend. It seems better to preserve the
invariant that a WORM key always contains the complete filename, since
the filename is the only unique material in the key, other than mtime and
size. Since nobody has complained about add failing (I think I saw it
once?) on WORM, probably it's ok, or nobody but me uses it.
There may be compatability problems if using git annex addurl --fast
or the WORM backend on a system with the 255 limit and then trying to use
that repo in a system with a smaller limit. I have not tried to deal with
those.
This commit was sponsored by Alexander Brem. Thanks!
Diffstat (limited to 'Command/AddUrl.hs')
-rw-r--r-- | Command/AddUrl.hs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs index 5c8c224f2..5591bc7ee 100644 --- a/Command/AddUrl.hs +++ b/Command/AddUrl.hs @@ -54,7 +54,8 @@ start relaxed optfile pathdepth s = go $ fromMaybe bad $ parseURI s bad = fromMaybe (error $ "bad url " ++ s) $ parseURI $ escapeURIString isUnescapedInURI s go url = do - let file = fromMaybe (url2file url pathdepth) optfile + pathmax <- liftIO $ fileNameLengthLimit "." + let file = fromMaybe (url2file url pathdepth pathmax) optfile showStart "addurl" file next $ perform relaxed s file @@ -122,7 +123,7 @@ download url file = do liftIO $ snd <$> Url.exists url headers , return Nothing ) - return $ Backend.URL.fromUrl url size + Backend.URL.fromUrl url size runtransfer dummykey tmp = Transfer.download webUUID dummykey (Just file) Transfer.forwardRetry $ const $ do liftIO $ createDirectoryIfMissing True (parentDir tmp) @@ -151,15 +152,15 @@ nodownload relaxed url file = do else liftIO $ Url.exists url headers if exists then do - let key = Backend.URL.fromUrl url size + key <- Backend.URL.fromUrl url size cleanup url file key Nothing else do warning $ "unable to access url: " ++ url return False -url2file :: URI -> Maybe Int -> FilePath -url2file url pathdepth = case pathdepth of - Nothing -> filesize $ escape fullurl +url2file :: URI -> Maybe Int -> Int -> FilePath +url2file url pathdepth pathmax = case pathdepth of + Nothing -> truncateFilePath pathmax $ escape fullurl Just depth | depth >= length urlbits -> frombits id | depth > 0 -> frombits $ drop depth @@ -168,7 +169,6 @@ url2file url pathdepth = case pathdepth of where fullurl = uriRegName auth ++ uriPath url ++ uriQuery url frombits a = intercalate "/" $ a urlbits - urlbits = map (filesize . escape) $ filter (not . null) $ split "/" fullurl + urlbits = map (truncateFilePath pathmax . escape) $ filter (not . null) $ split "/" fullurl auth = fromMaybe (error $ "bad url " ++ show url) $ uriAuthority url - filesize = take 255 escape = replace "/" "_" . replace "?" "_" |