annex.maxextensionlength

Added annex.maxextensionlength for use cases where extensions longer than 4
characters are needed.

This commit was sponsored by Henrik Riomar on Patreon.
This commit is contained in:
Joey Hess 2018-09-24 12:07:46 -04:00
parent 0f9eafc157
commit 4ecba916a1
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
9 changed files with 48 additions and 16 deletions

View file

@ -98,13 +98,16 @@ keyValue hash source = do
keyValueE :: Hash -> KeySource -> Annex (Maybe Key) keyValueE :: Hash -> KeySource -> Annex (Maybe Key)
keyValueE hash source = keyValue hash source >>= maybe (return Nothing) addE keyValueE hash source = keyValue hash source >>= maybe (return Nothing) addE
where where
addE k = return $ Just $ k addE k = do
{ keyName = keyName k ++ selectExtension (keyFilename source) maxlen <- annexMaxExtensionLength <$> Annex.getGitConfig
, keyVariety = hashKeyVariety hash (HasExt True) let ext = selectExtension maxlen (keyFilename source)
} return $ Just $ k
{ keyName = keyName k ++ ext
, keyVariety = hashKeyVariety hash (HasExt True)
}
selectExtension :: FilePath -> String selectExtension :: Maybe Int -> FilePath -> String
selectExtension f selectExtension maxlen f
| null es = "" | null es = ""
| otherwise = intercalate "." ("":es) | otherwise = intercalate "." ("":es)
where where
@ -112,7 +115,10 @@ selectExtension f
take 2 $ filter (all validInExtension) $ take 2 $ filter (all validInExtension) $
takeWhile shortenough $ takeWhile shortenough $
reverse $ splitc '.' $ takeExtensions f reverse $ splitc '.' $ takeExtensions f
shortenough e = length e <= 4 -- long enough for "jpeg" shortenough e = length e <= fromMaybe maxExtensionLen maxlen
maxExtensionLen :: Int
maxExtensionLen = 4 -- long enough for "jpeg"
{- A key's checksum is checked during fsck when it's content is present {- A key's checksum is checked during fsck when it's content is present
- except for in fast mode. -} - except for in fast mode. -}
@ -162,8 +168,12 @@ needsUpgrade key = or
, not (hasExt (keyVariety key)) && keyHash key /= keyName key , not (hasExt (keyVariety key)) && keyHash key /= keyName key
] ]
trivialMigrate :: Key -> Backend -> AssociatedFile -> Maybe Key trivialMigrate :: Key -> Backend -> AssociatedFile -> Annex (Maybe Key)
trivialMigrate oldkey newbackend afile trivialMigrate oldkey newbackend afile = trivialMigrate' oldkey newbackend afile
<$> (annexMaxExtensionLength <$> Annex.getGitConfig)
trivialMigrate' :: Key -> Backend -> AssociatedFile -> Maybe Int -> Maybe Key
trivialMigrate' oldkey newbackend afile maxextlen
{- Fast migration from hashE to hash backend. -} {- Fast migration from hashE to hash backend. -}
| migratable && hasExt oldvariety = Just $ oldkey | migratable && hasExt oldvariety = Just $ oldkey
{ keyName = keyHash oldkey { keyName = keyHash oldkey
@ -173,7 +183,8 @@ trivialMigrate oldkey newbackend afile
| migratable && hasExt newvariety = case afile of | migratable && hasExt newvariety = case afile of
AssociatedFile Nothing -> Nothing AssociatedFile Nothing -> Nothing
AssociatedFile (Just file) -> Just $ oldkey AssociatedFile (Just file) -> Just $ oldkey
{ keyName = keyHash oldkey ++ selectExtension file { keyName = keyHash oldkey
++ selectExtension maxextlen file
, keyVariety = newvariety , keyVariety = newvariety
} }
{- Upgrade to fix bad previous migration that created a {- Upgrade to fix bad previous migration that created a

View file

@ -47,11 +47,11 @@ keyValue source = do
needsUpgrade :: Key -> Bool needsUpgrade :: Key -> Bool
needsUpgrade key = ' ' `elem` keyName key needsUpgrade key = ' ' `elem` keyName key
removeSpaces :: Key -> Backend -> AssociatedFile -> Maybe Key removeSpaces :: Key -> Backend -> AssociatedFile -> Annex (Maybe Key)
removeSpaces oldkey newbackend _ removeSpaces oldkey newbackend _
| migratable = Just $ oldkey | migratable = return $ Just $ oldkey
{ keyName = reSanitizeKeyName (keyName oldkey) } { keyName = reSanitizeKeyName (keyName oldkey) }
| otherwise = Nothing | otherwise = return Nothing
where where
migratable = oldvariety == newvariety migratable = oldvariety == newvariety
oldvariety = keyVariety oldkey oldvariety = keyVariety oldkey

View file

@ -11,6 +11,8 @@ git-annex (6.20180914) UNRELEASED; urgency=medium
as the rest of git's interface is used in newline-safe ways. as the rest of git's interface is used in newline-safe ways.
* Added -z option to git-annex commands that use --batch, useful for * Added -z option to git-annex commands that use --batch, useful for
supporting filenames containing newlines. supporting filenames containing newlines.
* Added annex.maxextensionlength for use cases where extensions longer
than 4 characters are needed.
* More FreeBSD build fixes. * More FreeBSD build fixes.
[ Yaroslav Halchenko ] [ Yaroslav Halchenko ]

View file

@ -65,7 +65,7 @@ upgradableKey backend key = isNothing (keySize key) || backendupgradable
- generated. - generated.
-} -}
perform :: FilePath -> Key -> Backend -> Backend -> CommandPerform perform :: FilePath -> Key -> Backend -> Backend -> CommandPerform
perform file oldkey oldbackend newbackend = go =<< genkey perform file oldkey oldbackend newbackend = go =<< genkey (fastMigrate oldbackend)
where where
go Nothing = stop go Nothing = stop
go (Just (newkey, knowngoodcontent)) go (Just (newkey, knowngoodcontent))
@ -84,7 +84,8 @@ perform file oldkey oldbackend newbackend = go =<< genkey
next $ Command.ReKey.cleanup file oldkey newkey next $ Command.ReKey.cleanup file oldkey newkey
, error "failed" , error "failed"
) )
genkey = case maybe Nothing (\fm -> fm oldkey newbackend afile) (fastMigrate oldbackend) of genkey Nothing = return Nothing
genkey (Just fm) = fm oldkey newbackend afile >>= \case
Just newkey -> return $ Just (newkey, True) Just newkey -> return $ Just (newkey, True)
Nothing -> do Nothing -> do
content <- calcRepo $ gitAnnexLocation oldkey content <- calcRepo $ gitAnnexLocation oldkey

View file

@ -21,7 +21,7 @@ data BackendA a = Backend
, canUpgradeKey :: Maybe (Key -> Bool) , canUpgradeKey :: Maybe (Key -> Bool)
-- Checks if there is a fast way to migrate a key to a different -- Checks if there is a fast way to migrate a key to a different
-- backend (ie, without re-hashing). -- backend (ie, without re-hashing).
, fastMigrate :: Maybe (Key -> BackendA a -> AssociatedFile -> Maybe Key) , fastMigrate :: Maybe (Key -> BackendA a -> AssociatedFile -> a (Maybe Key))
-- Checks if a key is known (or assumed) to always refer to the -- Checks if a key is known (or assumed) to always refer to the
-- same data. -- same data.
, isStableKey :: Key -> Bool , isStableKey :: Key -> Bool

View file

@ -98,6 +98,7 @@ data GitConfig = GitConfig
, annexAllowedUrlSchemes :: S.Set Scheme , annexAllowedUrlSchemes :: S.Set Scheme
, annexAllowedHttpAddresses :: String , annexAllowedHttpAddresses :: String
, annexAllowUnverifiedDownloads :: Bool , annexAllowUnverifiedDownloads :: Bool
, annexMaxExtensionLength :: Maybe Int
, coreSymlinks :: Bool , coreSymlinks :: Bool
, coreSharedRepository :: SharedRepository , coreSharedRepository :: SharedRepository
, receiveDenyCurrentBranch :: DenyCurrentBranch , receiveDenyCurrentBranch :: DenyCurrentBranch
@ -171,6 +172,7 @@ extractGitConfig r = GitConfig
getmaybe (annex "security.allowed-http-addresses") getmaybe (annex "security.allowed-http-addresses")
, annexAllowUnverifiedDownloads = (== Just "ACKTHPPT") $ , annexAllowUnverifiedDownloads = (== Just "ACKTHPPT") $
getmaybe (annex "security.allow-unverified-downloads") getmaybe (annex "security.allow-unverified-downloads")
, annexMaxExtensionLength = getmayberead (annex "maxextensionlength")
, coreSymlinks = getbool "core.symlinks" True , coreSymlinks = getbool "core.symlinks" True
, coreSharedRepository = getSharedRepository r , coreSharedRepository = getSharedRepository r
, receiveDenyCurrentBranch = getDenyCurrentBranch r , receiveDenyCurrentBranch = getDenyCurrentBranch r

View file

@ -865,6 +865,13 @@ Here are all the supported configuration settings.
To configure the behavior in new clones of the repository, To configure the behavior in new clones of the repository,
this can be set in [[git-annex-config]]. this can be set in [[git-annex-config]].
* `annex.maxextensionlength`
Maximum length of what is considered a filename extension when adding a
file to a backend that preserves filename extensions. The default length
is 4, which allows extensions like "jpeg". The dot before the extension
is not counted part of its length.
* `annex.diskreserve` * `annex.diskreserve`
Amount of disk space to reserve. Disk space is checked when transferring Amount of disk space to reserve. Disk space is checked when transferring

View file

@ -3,3 +3,5 @@ file myfile.fasta becomes the symlink .git/annex/objects/xx/xx/key/myfile.fasta
.git/annex/objects/xx/xx/key/anotherfile.fasta which is a hardlink to myfile.fasta . An added plus is that the symlinks checked into git typically becomes shorter. Or, for better backwards compatibility, the symlinks checked into git don't change, but .git/annex/objects/xx/xx/key/anotherfile.fasta which is a hardlink to myfile.fasta . An added plus is that the symlinks checked into git typically becomes shorter. Or, for better backwards compatibility, the symlinks checked into git don't change, but
.git/annex/objects/xx/xx/key/key becomes a symlink to .git/annex/objects/xx/xx/key/myfile.fasta . However, if there is anotherfile.fasta with the same key, its symlink will still end up terminating at myfile.fasta rather than anotherfile.fasta . .git/annex/objects/xx/xx/key/key becomes a symlink to .git/annex/objects/xx/xx/key/myfile.fasta . However, if there is anotherfile.fasta with the same key, its symlink will still end up terminating at myfile.fasta rather than anotherfile.fasta .
It's useful to preserve full filenames, because it's not uncommon to e.g. encode parameter information in filenames (myresult.threshold100.dat); and it's not uncommon to call something like python's os.path.realpath to unwind symlink chains before processing a file. It's useful to preserve full filenames, because it's not uncommon to e.g. encode parameter information in filenames (myresult.threshold100.dat); and it's not uncommon to call something like python's os.path.realpath to unwind symlink chains before processing a file.
> [[done]] --[[Joey]]

View file

@ -0,0 +1,7 @@
[[!comment format=mdwn
username="joey"
subject="""comment 2"""
date="2018-09-24T15:50:47Z"
content="""
Added annex.maxextensionlength configuration.
"""]]