finished this stage of the RawFilePath conversion

This commit was sponsored by Denis Dzyubenko on Patreon.
This commit is contained in:
Joey Hess 2020-11-06 14:10:58 -04:00
parent 2c8cf06e75
commit 1db49497e0
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
27 changed files with 100 additions and 93 deletions

View file

@ -72,12 +72,12 @@ start fixwhat si file key = do
breakHardLink :: RawFilePath -> Key -> RawFilePath -> CommandPerform
breakHardLink file key obj = do
replaceWorkTreeFile (fromRawFilePath file) $ \tmp -> do
let tmp' = toRawFilePath tmp
mode <- liftIO $ catchMaybeIO $ fileMode <$> R.getFileStatus file
let obj' = fromRawFilePath obj
unlessM (checkedCopyFile key obj' tmp mode) $
unlessM (checkedCopyFile key obj tmp' mode) $
error "unable to break hard link"
thawContent tmp
modifyContent obj $ freezeContent obj'
thawContent tmp'
modifyContent obj $ freezeContent obj
Database.Keys.storeInodeCaches key [file]
next $ return True

View file

@ -183,7 +183,7 @@ performRemote key afile backend numcopies remote =
let cleanup = liftIO $ catchIO (R.removeLink tmp) (const noop)
cleanup
cleanup `after` a tmp
getfile tmp = ifM (checkDiskSpace (Just (fromRawFilePath (P.takeDirectory tmp))) key 0 True)
getfile tmp = ifM (checkDiskSpace (Just (P.takeDirectory tmp)) key 0 True)
( ifM (getcheap tmp)
( return (Just True)
, ifM (Annex.getState Annex.fast)
@ -251,9 +251,9 @@ verifyLocationLog key keystatus ai = do
- in a permission fixup here too. -}
when present $ do
void $ tryIO $ case keystatus of
KeyUnlockedThin -> thawContent (fromRawFilePath obj)
KeyLockedThin -> thawContent (fromRawFilePath obj)
_ -> freezeContent (fromRawFilePath obj)
KeyUnlockedThin -> thawContent obj
KeyLockedThin -> thawContent obj
_ -> freezeContent obj
unlessM (isContentWritePermOk obj) $
warning $ "** Unable to set correct write mode for " ++ fromRawFilePath obj ++ " ; perhaps you don't own that file"
whenM (liftIO $ R.doesPathExist $ parentDir obj) $
@ -346,13 +346,14 @@ verifyWorkTree key file = do
Just k | k == key -> whenM (inAnnex key) $ do
showNote "fixing worktree content"
replaceWorkTreeFile (fromRawFilePath file) $ \tmp -> do
let tmp' = toRawFilePath tmp
mode <- liftIO $ catchMaybeIO $ fileMode <$> R.getFileStatus file
ifM (annexThin <$> Annex.getGitConfig)
( void $ linkFromAnnex key (toRawFilePath tmp) mode
( void $ linkFromAnnex key tmp' mode
, do
obj <- fromRawFilePath <$> calcRepo (gitAnnexLocation key)
void $ checkedCopyFile key obj tmp mode
thawContent tmp
obj <- calcRepo (gitAnnexLocation key)
void $ checkedCopyFile key obj tmp' mode
thawContent tmp'
)
Database.Keys.storeInodeCaches key [file]
_ -> return ()
@ -586,17 +587,16 @@ recordFsckTime inc key = withFsckDb inc $ \h -> liftIO $ FsckDb.addDb h key
recordStartTime :: UUID -> Annex ()
recordStartTime u = do
f <- fromRepo (gitAnnexFsckState u)
let f' = fromRawFilePath f
createAnnexDirectory $ parentDir f
liftIO $ removeWhenExistsWith R.removeLink f
liftIO $ withFile f' WriteMode $ \h -> do
liftIO $ withFile (fromRawFilePath f) WriteMode $ \h -> do
#ifndef mingw32_HOST_OS
t <- modificationTime <$> R.getFileStatus f
#else
t <- getPOSIXTime
#endif
hPutStr h $ showTime $ realToFrac t
setAnnexFilePerm f'
setAnnexFilePerm f
where
showTime :: POSIXTime -> String
showTime = show

View file

@ -70,16 +70,15 @@ perform file key = do
, repopulate obj
)
whenM (liftIO $ R.doesPathExist obj) $
freezeContent $ fromRawFilePath obj
freezeContent obj
-- It's ok if the file is hard linked to obj, but if some other
-- associated file is, we need to break that link to lock down obj.
breakhardlink obj = whenM (catchBoolIO $ (> 1) . linkCount <$> liftIO (R.getFileStatus obj)) $ do
mfc <- withTSDelta (liftIO . genInodeCache file)
unlessM (sameInodeCache obj (maybeToList mfc)) $ do
let obj' = fromRawFilePath obj
modifyContent obj $ replaceGitAnnexDirFile obj' $ \tmp -> do
unlessM (checkedCopyFile key obj' tmp Nothing) $
modifyContent obj $ replaceGitAnnexDirFile (fromRawFilePath obj) $ \tmp -> do
unlessM (checkedCopyFile key obj (toRawFilePath tmp) Nothing) $
giveup "unable to lock file"
Database.Keys.storeInodeCaches key [obj]
@ -92,7 +91,7 @@ perform file key = do
liftIO $ removeWhenExistsWith R.removeLink obj
case mfile of
Just unmodified ->
unlessM (checkedCopyFile key (fromRawFilePath unmodified) (fromRawFilePath obj) Nothing)
unlessM (checkedCopyFile key unmodified obj Nothing)
lostcontent
Nothing -> lostcontent

View file

@ -220,11 +220,11 @@ wormholePairing remotename ouraddrs ui = do
-- to read them. So, set up a temp directory that only
-- we can read.
withTmpDir "pair" $ \tmp -> do
liftIO $ void $ tryIO $ modifyFileMode tmp $
liftIO $ void $ tryIO $ modifyFileMode (toRawFilePath tmp) $
removeModes otherGroupModes
let sendf = tmp </> "send"
let recvf = tmp </> "recv"
liftIO $ writeFileProtected sendf $
liftIO $ writeFileProtected (toRawFilePath sendf) $
serializePairData ourpairdata
observer <- liftIO Wormhole.mkCodeObserver

View file

@ -96,15 +96,16 @@ linkKey file oldkey newkey = ifM (isJust <$> isAnnexLink file)
, do
{- The file being rekeyed is itself an unlocked file; if
- it's hard linked to the old key, that link must be broken. -}
oldobj <- fromRawFilePath <$> calcRepo (gitAnnexLocation oldkey)
oldobj <- calcRepo (gitAnnexLocation oldkey)
v <- tryNonAsync $ do
st <- liftIO $ R.getFileStatus file
when (linkCount st > 1) $ do
freezeContent oldobj
replaceWorkTreeFile (fromRawFilePath file) $ \tmp -> do
unlessM (checkedCopyFile oldkey oldobj tmp Nothing) $
let tmp' = toRawFilePath tmp
unlessM (checkedCopyFile oldkey oldobj tmp' Nothing) $
error "can't lock old key"
thawContent tmp
thawContent tmp'
ic <- withTSDelta (liftIO . genInodeCache file)
case v of
Left e -> do

View file

@ -14,6 +14,7 @@ import qualified Annex.Branch
import qualified Git.Ref
import Git.Types
import Annex.Version
import qualified Utility.RawFilePath as R
cmd :: Command
cmd = noCommit $ dontCheck repoExists $
@ -75,7 +76,7 @@ repairAnnexBranch modifiedbranches
Annex.Branch.forceCommit "committing index after git repository repair"
liftIO $ putStrLn "Successfully recovered the git-annex branch using .git/annex/index"
nukeindex = do
inRepo $ removeWhenExistsWith removeLink . gitAnnexIndex
inRepo $ removeWhenExistsWith R.removeLink . gitAnnexIndex
liftIO $ putStrLn "Had to delete the .git/annex/index file as it was corrupt."
missingbranch = liftIO $ putStrLn "Since the git-annex branch is not up-to-date anymore. It would be a very good idea to run: git annex fsck --fast"

View file

@ -14,6 +14,7 @@ import qualified Git.Command
import Utility.CopyFile
import qualified Database.Keys
import Git.FilePath
import qualified Utility.RawFilePath as R
cmd :: Command
cmd = withGlobalOptions [annexedMatchingOptions] $
@ -54,7 +55,7 @@ perform file key = do
cleanup :: RawFilePath -> Key -> CommandCleanup
cleanup file key = do
Database.Keys.removeAssociatedFile key =<< inRepo (toTopFilePath file)
src <- fromRawFilePath <$> calcRepo (gitAnnexLocation key)
src <- calcRepo (gitAnnexLocation key)
ifM (Annex.getState Annex.fast)
( do
-- Only make a hard link if the annexed file does not
@ -62,19 +63,21 @@ cleanup file key = do
-- This avoids unannexing (and uninit) ending up
-- hard linking files together, which would be
-- surprising.
s <- liftIO $ getFileStatus src
s <- liftIO $ R.getFileStatus src
if linkCount s > 1
then copyfrom src
else hardlinkfrom src
, copyfrom src
)
where
file' = fromRawFilePath file
copyfrom src =
thawContent file' `after` liftIO (copyFileExternal CopyAllMetaData src file')
thawContent file `after` liftIO
(copyFileExternal CopyAllMetaData
(fromRawFilePath src)
(fromRawFilePath file))
hardlinkfrom src =
-- creating a hard link could fall; fall back to copying
ifM (liftIO $ catchBoolIO $ createLink src file' >> return True)
ifM (liftIO $ catchBoolIO $ R.createLink src file >> return True)
( return True
, copyfrom src
)

View file

@ -73,7 +73,7 @@ finish = do
then liftIO $ removeDirectoryRecursive annexdir
else giveup $ unlines
[ "Not fully uninitialized"
, "Some annexed data is still left in " ++ annexobjectdir
, "Some annexed data is still left in " ++ fromRawFilePath annexobjectdir
, "This may include deleted files, or old versions of modified files."
, ""
, "If you don't care about preserving the data, just delete the"
@ -108,7 +108,7 @@ prepareRemoveAnnexDir annexdir = do
prepareRemoveAnnexDir' :: FilePath -> IO ()
prepareRemoveAnnexDir' annexdir =
dirTreeRecursiveSkipping (const False) annexdir
>>= mapM_ (void . tryIO . allowWrite)
>>= mapM_ (void . tryIO . allowWrite . toRawFilePath)
{- Keys that were moved out of the annex have a hard link still in the
- annex, with > 1 link count, and those can be removed.