ensure that content directory is thawed when writing direct mode mapping and cache files
This commit is contained in:
parent
21a7ab4592
commit
103b572d8e
4 changed files with 37 additions and 34 deletions
|
@ -27,8 +27,6 @@ module Annex.Content (
|
||||||
preseedTmp,
|
preseedTmp,
|
||||||
freezeContent,
|
freezeContent,
|
||||||
thawContent,
|
thawContent,
|
||||||
freezeContentDir,
|
|
||||||
createContentDir,
|
|
||||||
replaceFile,
|
replaceFile,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
@ -457,27 +455,3 @@ thawContent file = liftIO . go =<< fromRepo getSharedRepository
|
||||||
go GroupShared = groupWriteRead file
|
go GroupShared = groupWriteRead file
|
||||||
go AllShared = groupWriteRead file
|
go AllShared = groupWriteRead file
|
||||||
go _ = allowWrite file
|
go _ = allowWrite file
|
||||||
|
|
||||||
{- Blocks writing to the directory an annexed file is in, to prevent the
|
|
||||||
- file accidentially being deleted. However, if core.sharedRepository
|
|
||||||
- is set, this is not done, since the group must be allowed to delete the
|
|
||||||
- file.
|
|
||||||
-}
|
|
||||||
freezeContentDir :: FilePath -> Annex ()
|
|
||||||
freezeContentDir file = liftIO . go =<< fromRepo getSharedRepository
|
|
||||||
where
|
|
||||||
dir = parentDir file
|
|
||||||
go GroupShared = groupWriteRead dir
|
|
||||||
go AllShared = groupWriteRead dir
|
|
||||||
go _ = preventWrite dir
|
|
||||||
|
|
||||||
{- Makes the directory tree to store an annexed file's content,
|
|
||||||
- with appropriate permissions on each level. -}
|
|
||||||
createContentDir :: FilePath -> Annex ()
|
|
||||||
createContentDir dest = do
|
|
||||||
unlessM (liftIO $ doesDirectoryExist dir) $
|
|
||||||
createAnnexDirectory dir
|
|
||||||
-- might have already existed with restricted perms
|
|
||||||
liftIO $ allowWrite dir
|
|
||||||
where
|
|
||||||
dir = parentDir dest
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ module Annex.Content.Direct (
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
|
import Annex.Perms
|
||||||
import qualified Git
|
import qualified Git
|
||||||
import Utility.TempFile
|
import Utility.TempFile
|
||||||
import Logs.Location
|
import Logs.Location
|
||||||
|
@ -53,7 +54,8 @@ changeAssociatedFiles key transform = do
|
||||||
mapping <- inRepo $ gitAnnexMapping key
|
mapping <- inRepo $ gitAnnexMapping key
|
||||||
files <- associatedFilesRelative key
|
files <- associatedFilesRelative key
|
||||||
let files' = transform files
|
let files' = transform files
|
||||||
when (files /= files') $
|
when (files /= files') $ do
|
||||||
|
createContentDir mapping
|
||||||
liftIO $ viaTmp write mapping $ unlines files'
|
liftIO $ viaTmp write mapping $ unlines files'
|
||||||
top <- fromRepo Git.repoPath
|
top <- fromRepo Git.repoPath
|
||||||
return $ map (top </>) files'
|
return $ map (top </>) files'
|
||||||
|
@ -109,7 +111,7 @@ changedFileStatus key status = do
|
||||||
{- Gets the recorded cache for a key. -}
|
{- Gets the recorded cache for a key. -}
|
||||||
recordedCache :: Key -> Annex (Maybe Cache)
|
recordedCache :: Key -> Annex (Maybe Cache)
|
||||||
recordedCache key = withCacheFile key $ \cachefile ->
|
recordedCache key = withCacheFile key $ \cachefile ->
|
||||||
catchDefaultIO Nothing $ readCache <$> readFile cachefile
|
liftIO $ catchDefaultIO Nothing $ readCache <$> readFile cachefile
|
||||||
|
|
||||||
{- Compares a cache with the current cache for a file. -}
|
{- Compares a cache with the current cache for a file. -}
|
||||||
compareCache :: FilePath -> Maybe Cache -> Annex Bool
|
compareCache :: FilePath -> Maybe Cache -> Annex Bool
|
||||||
|
@ -124,12 +126,14 @@ updateCache key file = maybe noop (writeCache key) =<< liftIO (genCache file)
|
||||||
{- Writes a cache for a key. -}
|
{- Writes a cache for a key. -}
|
||||||
writeCache :: Key -> Cache -> Annex ()
|
writeCache :: Key -> Cache -> Annex ()
|
||||||
writeCache key cache = withCacheFile key $ \cachefile -> do
|
writeCache key cache = withCacheFile key $ \cachefile -> do
|
||||||
createDirectoryIfMissing True (parentDir cachefile)
|
createContentDir cachefile
|
||||||
writeFile cachefile $ showCache cache
|
liftIO $ writeFile cachefile $ showCache cache
|
||||||
|
|
||||||
{- Removes a cache. -}
|
{- Removes a cache. -}
|
||||||
removeCache :: Key -> Annex ()
|
removeCache :: Key -> Annex ()
|
||||||
removeCache key = withCacheFile key nukeFile
|
removeCache key = withCacheFile key $ \f -> do
|
||||||
|
createContentDir f -- also thaws directory
|
||||||
|
liftIO $ nukeFile f
|
||||||
|
|
||||||
{- Cache a file's inode, size, and modification time to determine if it's
|
{- Cache a file's inode, size, and modification time to determine if it's
|
||||||
- been changed. -}
|
- been changed. -}
|
||||||
|
@ -166,5 +170,5 @@ toCache s
|
||||||
(modificationTime s)
|
(modificationTime s)
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
|
|
||||||
withCacheFile :: Key -> (FilePath -> IO a) -> Annex a
|
withCacheFile :: Key -> (FilePath -> Annex a) -> Annex a
|
||||||
withCacheFile key a = liftIO . a =<< inRepo (gitAnnexCache key)
|
withCacheFile key a = a =<< inRepo (gitAnnexCache key)
|
||||||
|
|
|
@ -171,7 +171,6 @@ toDirect k f = maybe noop id =<< toDirectGen k f
|
||||||
toDirectGen :: Key -> FilePath -> Annex (Maybe (Annex ()))
|
toDirectGen :: Key -> FilePath -> Annex (Maybe (Annex ()))
|
||||||
toDirectGen k f = do
|
toDirectGen k f = do
|
||||||
loc <- inRepo $ gitAnnexLocation k
|
loc <- inRepo $ gitAnnexLocation k
|
||||||
createContentDir loc -- thaws directory too
|
|
||||||
absf <- liftIO $ absPath f
|
absf <- liftIO $ absPath f
|
||||||
locs <- filter (/= absf) <$> addAssociatedFile k f
|
locs <- filter (/= absf) <$> addAssociatedFile k f
|
||||||
case locs of
|
case locs of
|
||||||
|
|
|
@ -10,6 +10,8 @@ module Annex.Perms (
|
||||||
annexFileMode,
|
annexFileMode,
|
||||||
createAnnexDirectory,
|
createAnnexDirectory,
|
||||||
noUmask,
|
noUmask,
|
||||||
|
createContentDir,
|
||||||
|
freezeContentDir,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
|
@ -68,3 +70,27 @@ createAnnexDirectory dir = traverse dir [] =<< top
|
||||||
done = forM_ below $ \p -> do
|
done = forM_ below $ \p -> do
|
||||||
liftIO $ createDirectory p
|
liftIO $ createDirectory p
|
||||||
setAnnexPerm p
|
setAnnexPerm p
|
||||||
|
|
||||||
|
{- Blocks writing to the directory an annexed file is in, to prevent the
|
||||||
|
- file accidentially being deleted. However, if core.sharedRepository
|
||||||
|
- is set, this is not done, since the group must be allowed to delete the
|
||||||
|
- file.
|
||||||
|
-}
|
||||||
|
freezeContentDir :: FilePath -> Annex ()
|
||||||
|
freezeContentDir file = liftIO . go =<< fromRepo getSharedRepository
|
||||||
|
where
|
||||||
|
dir = parentDir file
|
||||||
|
go GroupShared = groupWriteRead dir
|
||||||
|
go AllShared = groupWriteRead dir
|
||||||
|
go _ = preventWrite dir
|
||||||
|
|
||||||
|
{- Makes the directory tree to store an annexed file's content,
|
||||||
|
- with appropriate permissions on each level. -}
|
||||||
|
createContentDir :: FilePath -> Annex ()
|
||||||
|
createContentDir dest = do
|
||||||
|
unlessM (liftIO $ doesDirectoryExist dir) $
|
||||||
|
createAnnexDirectory dir
|
||||||
|
-- might have already existed with restricted perms
|
||||||
|
liftIO $ allowWrite dir
|
||||||
|
where
|
||||||
|
dir = parentDir dest
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue