key conversion back from file bugfixes
This commit is contained in:
parent
cc5cf0093e
commit
99b2029236
3 changed files with 21 additions and 18 deletions
6
Annex.hs
6
Annex.hs
|
@ -87,10 +87,8 @@ annexFile state file = inBackend file err $ do
|
||||||
{- Inverse of annexFile. -}
|
{- Inverse of annexFile. -}
|
||||||
unannexFile :: State -> FilePath -> IO ()
|
unannexFile :: State -> FilePath -> IO ()
|
||||||
unannexFile state file = notinBackend file err $ \(key, backend) -> do
|
unannexFile state file = notinBackend file err $ \(key, backend) -> do
|
||||||
dropped <- dropFile state backend key
|
dropFile state backend key
|
||||||
if (not dropped)
|
cleanup key backend
|
||||||
then error $ "backend refused to drop " ++ file
|
|
||||||
else cleanup key backend
|
|
||||||
where
|
where
|
||||||
err = error $ "not annexed " ++ file
|
err = error $ "not annexed " ++ file
|
||||||
cleanup key backend = do
|
cleanup key backend = do
|
||||||
|
|
|
@ -69,5 +69,5 @@ lookupFile file = do
|
||||||
lookup = do
|
lookup = do
|
||||||
l <- readSymbolicLink file
|
l <- readSymbolicLink file
|
||||||
return $ Just (k l, b l)
|
return $ Just (k l, b l)
|
||||||
k l = Key $ takeFileName $ l
|
k l = fileKey $ takeFileName $ l
|
||||||
b l = lookupBackendName $ takeFileName $ parentDir $ l
|
b l = lookupBackendName $ takeFileName $ parentDir $ l
|
||||||
|
|
31
Locations.hs
31
Locations.hs
|
@ -5,6 +5,7 @@ module Locations (
|
||||||
gitStateDir,
|
gitStateDir,
|
||||||
stateLoc,
|
stateLoc,
|
||||||
keyFile,
|
keyFile,
|
||||||
|
fileKey,
|
||||||
annexLocation,
|
annexLocation,
|
||||||
annexLocationRelative
|
annexLocationRelative
|
||||||
) where
|
) where
|
||||||
|
@ -19,19 +20,6 @@ stateLoc = ".git-annex"
|
||||||
gitStateDir :: GitRepo -> FilePath
|
gitStateDir :: GitRepo -> FilePath
|
||||||
gitStateDir repo = (gitWorkTree repo) ++ "/" ++ stateLoc ++ "/"
|
gitStateDir repo = (gitWorkTree repo) ++ "/" ++ stateLoc ++ "/"
|
||||||
|
|
||||||
{- Converts a key into a filename fragment.
|
|
||||||
-
|
|
||||||
- Escape "/" in the key name, to keep a flat tree of files and avoid
|
|
||||||
- issues with keys containing "/../" or ending with "/" etc.
|
|
||||||
-
|
|
||||||
- "/" is escaped to "%" because it's short and rarely used, and resembles
|
|
||||||
- a slash
|
|
||||||
- "%" is escaped to "&s", and "&" to "&a"; this ensures that the mapping
|
|
||||||
- is one to one.
|
|
||||||
- -}
|
|
||||||
keyFile :: Key -> FilePath
|
|
||||||
keyFile key = replace "/" "%" $ replace "%" "%s" $ replace "&" "&a" $ show key
|
|
||||||
|
|
||||||
{- An annexed file's content is stored in
|
{- An annexed file's content is stored in
|
||||||
- .git/annex/<backend>/<key> ; this allows deriving the key and backend
|
- .git/annex/<backend>/<key> ; this allows deriving the key and backend
|
||||||
- by looking at the symlink to it. -}
|
- by looking at the symlink to it. -}
|
||||||
|
@ -45,3 +33,20 @@ annexLocationRelative :: State -> Backend -> Key -> FilePath
|
||||||
annexLocationRelative state backend key =
|
annexLocationRelative state backend key =
|
||||||
gitDir (repo state) ++ "/annex/" ++ (name backend) ++
|
gitDir (repo state) ++ "/annex/" ++ (name backend) ++
|
||||||
"/" ++ (keyFile key)
|
"/" ++ (keyFile key)
|
||||||
|
|
||||||
|
{- Converts a key into a filename fragment.
|
||||||
|
-
|
||||||
|
- Escape "/" in the key name, to keep a flat tree of files and avoid
|
||||||
|
- issues with keys containing "/../" or ending with "/" etc.
|
||||||
|
-
|
||||||
|
- "/" is escaped to "%" because it's short and rarely used, and resembles
|
||||||
|
- a slash
|
||||||
|
- "%" is escaped to "&s", and "&" to "&a"; this ensures that the mapping
|
||||||
|
- is one to one.
|
||||||
|
- -}
|
||||||
|
keyFile :: Key -> FilePath
|
||||||
|
keyFile key = replace "/" "%" $ replace "%" "&s" $ replace "&" "&a" $ show key
|
||||||
|
|
||||||
|
{- Reverses keyFile -}
|
||||||
|
fileKey :: FilePath -> Key
|
||||||
|
fileKey file = Key $ replace "&a" "&" $ replace "&s" "%" $ replace "%" "/" file
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue