init: Display an additional message when it detects a filesystem that allows writing to files whose write bit is not set.

This commit is contained in:
Joey Hess 2017-08-28 13:21:18 -04:00
parent 291d5bb471
commit db2a06b66f
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 40 additions and 12 deletions

View file

@ -146,32 +146,40 @@ probeCrippledFileSystem :: Annex Bool
probeCrippledFileSystem = do
tmp <- fromRepo gitAnnexTmpMiscDir
createAnnexDirectory tmp
liftIO $ probeCrippledFileSystem' tmp
probeCrippledFileSystem' tmp
probeCrippledFileSystem' :: FilePath -> IO Bool
probeCrippledFileSystem' :: FilePath -> Annex Bool
#ifdef mingw32_HOST_OS
probeCrippledFileSystem' _ = return True
#else
probeCrippledFileSystem' tmp = do
let f = tmp </> "gaprobe"
writeFile f ""
liftIO $ writeFile f ""
uncrippled <- probe f
void $ tryIO $ allowWrite f
removeFile f
void $ liftIO $ tryIO $ allowWrite f
liftIO $ removeFile f
return $ not uncrippled
where
probe f = catchBoolIO $ do
let f2 = f ++ "2"
nukeFile f2
createSymbolicLink f f2
nukeFile f2
preventWrite f
liftIO $ nukeFile f2
liftIO $ createSymbolicLink f f2
liftIO $ nukeFile f2
liftIO $ preventWrite f
-- Should be unable to write to the file, unless
-- running as root, but some crippled
-- filesystems ignore write bit removals.
ifM ((== 0) <$> getRealUserID)
ifM ((== 0) <$> liftIO getRealUserID)
( return True
, not <$> catchBoolIO (writeFile f "2" >> return True)
, do
r <- liftIO $ catchBoolIO $
writeFile f "2" >> return True
if r
then do
warning "Filesystem allows writing to files whose write bit is not set."
return False
else return True
)
#endif

View file

@ -1,6 +1,8 @@
git-annex (6.20170819) UNRELEASED; urgency=medium
* Support building with feed-1.0, while still supporting older versions.
* init: Display an additional message when it detects a filesystem that
allows writing to files whose write bit is not set.
-- Joey Hess <id@joeyh.name> Mon, 28 Aug 2017 12:20:59 -0400

View file

@ -147,7 +147,7 @@ runner = Just go
exitWith exitcode
runsubprocesstests opts (Just _) = isolateGitConfig $ do
ensuretmpdir
crippledfilesystem <- Annex.Init.probeCrippledFileSystem' tmpdir
crippledfilesystem <- annexeval $ Annex.Init.probeCrippledFileSystem' tmpdir
case tryIngredients ingredients (tastyOptionSet opts) (tests crippledfilesystem opts) of
Nothing -> error "No tests found!?"
Just act -> ifM act

View file

@ -60,3 +60,4 @@ git-annex-6.20170519-1.fc26.x86_64
I love git-annex.
> [[done]] --[[Joey]]

View file

@ -0,0 +1,17 @@
[[!comment format=mdwn
username="joey"
subject="""comment 1"""
date="2017-08-28T17:06:35Z"
content="""
git-annex has detected problems with the filesystem, since symlinks
work I think it detected that the filesystem allows writing to a
file even when the file's write bit is not set.
In that situation, a git-annex repository using symlinks will apprear to
work, but if you have an annexed file "foo" in there, and run "echo hi >
foo", it will follow the symlink, and overwrite the annexed file, ignoring
the lack of write bit. This can result in data loss in an unexpected way,
which is why git-annex avoids using the symlinks in this situation.
I've added an additional message to make more clear what is happening.
"""]]