2010-10-15 20:42:36 +00:00
|
|
|
{- git-annex "WORM" backend -- Write Once, Read Many
|
2010-10-27 20:53:54 +00:00
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2010 Joey Hess <id@joeyh.name>
|
2010-10-27 20:53:54 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
2010-10-15 20:42:36 +00:00
|
|
|
|
2011-03-02 17:47:45 +00:00
|
|
|
module Backend.WORM (backends) where
|
2010-10-15 20:42:36 +00:00
|
|
|
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2011-06-02 01:56:04 +00:00
|
|
|
import Types.Backend
|
|
|
|
import Types.Key
|
2012-06-20 20:07:14 +00:00
|
|
|
import Types.KeySource
|
Better sanitization of problem characters when generating URL and WORM keys.
FAT has a lot of characters it does not allow in filenames, like ? and *
It's probably the worst offender, but other filesystems also have
limitiations.
In 2011, I made keyFile escape : to handle FAT, but missed the other
characters. It also turns out that when I did that, I was also living
dangerously; any existing keys that contained a : had their object
location change. Oops.
So, adding new characters to escape to keyFile is out. Well, it would be
possible to make keyFile behave differently on a per-filesystem basis, but
this would be a real nightmare to get right. Consider that a rsync special
remote uses keyFile to determine the filenames to use, and we don't know
the underlying filesystem on the rsync server..
Instead, I have gone for a solution that is backwards compatable and
simple. Its only downside is that already generated URL and WORM keys
might not be able to be stored on FAT or some other filesystem that
dislikes a character used in the key. (In this case, the user can just
migrate the problem keys to a checksumming backend. If this became a big
problem, fsck could be made to detect these and suggest a migration.)
Going forward, new keys that are created will escape all characters that
are likely to cause problems. And if some filesystem comes along that's
even worse than FAT (seems unlikely, but here it is 2013, and people are
still using FAT!), additional characters can be added to the set that are
escaped without difficulty.
(Also, made WORM limit the part of the filename that is embedded in the key,
to deal with filesystem filename length limits. This could have already
been a problem, but is more likely now, since the escaping of the filename
can make it longer.)
This commit was sponsored by Ian Downes
2013-10-05 19:01:49 +00:00
|
|
|
import Backend.Utilities
|
2014-09-11 18:50:18 +00:00
|
|
|
import Git.FilePath
|
2010-10-16 20:20:49 +00:00
|
|
|
|
2011-12-31 08:11:39 +00:00
|
|
|
backends :: [Backend]
|
2011-03-02 17:47:45 +00:00
|
|
|
backends = [backend]
|
|
|
|
|
2011-12-31 08:11:39 +00:00
|
|
|
backend :: Backend
|
2012-06-05 23:51:03 +00:00
|
|
|
backend = Backend
|
|
|
|
{ name = "WORM"
|
|
|
|
, getKey = keyValue
|
|
|
|
, fsckKey = Nothing
|
2012-12-20 19:43:14 +00:00
|
|
|
, canUpgradeKey = Nothing
|
2014-07-10 21:06:04 +00:00
|
|
|
, fastMigrate = Nothing
|
2014-07-27 16:33:46 +00:00
|
|
|
, isStableKey = const True
|
2012-06-05 23:51:03 +00:00
|
|
|
}
|
2010-10-15 20:42:36 +00:00
|
|
|
|
2011-03-16 01:34:13 +00:00
|
|
|
{- The key includes the file size, modification time, and the
|
2014-09-11 18:50:18 +00:00
|
|
|
- original filename relative to the top of the git repository.
|
2011-03-16 01:34:13 +00:00
|
|
|
-}
|
2012-06-05 23:51:03 +00:00
|
|
|
keyValue :: KeySource -> Annex (Maybe Key)
|
|
|
|
keyValue source = do
|
2015-01-20 20:58:48 +00:00
|
|
|
let f = contentLocation source
|
|
|
|
stat <- liftIO $ getFileStatus f
|
|
|
|
sz <- liftIO $ getFileSize' f stat
|
2014-09-11 18:50:18 +00:00
|
|
|
relf <- getTopFilePath <$> inRepo (toTopFilePath $ keyFilename source)
|
2014-07-24 17:36:23 +00:00
|
|
|
return $ Just $ stubKey
|
2015-01-06 21:58:57 +00:00
|
|
|
{ keyName = genKeyName relf
|
Better sanitization of problem characters when generating URL and WORM keys.
FAT has a lot of characters it does not allow in filenames, like ? and *
It's probably the worst offender, but other filesystems also have
limitiations.
In 2011, I made keyFile escape : to handle FAT, but missed the other
characters. It also turns out that when I did that, I was also living
dangerously; any existing keys that contained a : had their object
location change. Oops.
So, adding new characters to escape to keyFile is out. Well, it would be
possible to make keyFile behave differently on a per-filesystem basis, but
this would be a real nightmare to get right. Consider that a rsync special
remote uses keyFile to determine the filenames to use, and we don't know
the underlying filesystem on the rsync server..
Instead, I have gone for a solution that is backwards compatable and
simple. Its only downside is that already generated URL and WORM keys
might not be able to be stored on FAT or some other filesystem that
dislikes a character used in the key. (In this case, the user can just
migrate the problem keys to a checksumming backend. If this became a big
problem, fsck could be made to detect these and suggest a migration.)
Going forward, new keys that are created will escape all characters that
are likely to cause problems. And if some filesystem comes along that's
even worse than FAT (seems unlikely, but here it is 2013, and people are
still using FAT!), additional characters can be added to the set that are
escaped without difficulty.
(Also, made WORM limit the part of the filename that is embedded in the key,
to deal with filesystem filename length limits. This could have already
been a problem, but is more likely now, since the escaping of the filename
can make it longer.)
This commit was sponsored by Ian Downes
2013-10-05 19:01:49 +00:00
|
|
|
, keyBackendName = name backend
|
2015-01-20 20:58:48 +00:00
|
|
|
, keySize = Just sz
|
Better sanitization of problem characters when generating URL and WORM keys.
FAT has a lot of characters it does not allow in filenames, like ? and *
It's probably the worst offender, but other filesystems also have
limitiations.
In 2011, I made keyFile escape : to handle FAT, but missed the other
characters. It also turns out that when I did that, I was also living
dangerously; any existing keys that contained a : had their object
location change. Oops.
So, adding new characters to escape to keyFile is out. Well, it would be
possible to make keyFile behave differently on a per-filesystem basis, but
this would be a real nightmare to get right. Consider that a rsync special
remote uses keyFile to determine the filenames to use, and we don't know
the underlying filesystem on the rsync server..
Instead, I have gone for a solution that is backwards compatable and
simple. Its only downside is that already generated URL and WORM keys
might not be able to be stored on FAT or some other filesystem that
dislikes a character used in the key. (In this case, the user can just
migrate the problem keys to a checksumming backend. If this became a big
problem, fsck could be made to detect these and suggest a migration.)
Going forward, new keys that are created will escape all characters that
are likely to cause problems. And if some filesystem comes along that's
even worse than FAT (seems unlikely, but here it is 2013, and people are
still using FAT!), additional characters can be added to the set that are
escaped without difficulty.
(Also, made WORM limit the part of the filename that is embedded in the key,
to deal with filesystem filename length limits. This could have already
been a problem, but is more likely now, since the escaping of the filename
can make it longer.)
This commit was sponsored by Ian Downes
2013-10-05 19:01:49 +00:00
|
|
|
, keyMtime = Just $ modificationTime stat
|
|
|
|
}
|