FileMode,
setAnnexFilePerm,
setAnnexDirPerm,
+ resetAnnexFilePerm,
annexFileMode,
createAnnexDirectory,
createWorkTreeDirectory,
{- Sets appropriate file mode for a file or directory in the annex,
- other than the content files and content directory. Normally,
- - use the default mode, but with core.sharedRepository set,
+ - don't change the mode, but with core.sharedRepository set,
- allow the group to write, etc. -}
setAnnexPerm :: Bool -> FilePath -> Annex ()
-setAnnexPerm isdir file = unlessM crippledFileSystem $
+setAnnexPerm = setAnnexPerm' Nothing
+
+setAnnexPerm' :: Maybe ([FileMode] -> FileMode -> FileMode) -> Bool -> FilePath -> Annex ()
+setAnnexPerm' modef isdir file = unlessM crippledFileSystem $
withShared $ liftIO . go
where
- go GroupShared = void $ tryIO $ modifyFileMode file $ addModes $
+ go GroupShared = void $ tryIO $ modifyFileMode file $ modef' $
groupSharedModes ++
if isdir then [ ownerExecuteMode, groupExecuteMode ] else []
- go AllShared = void $ tryIO $ modifyFileMode file $ addModes $
+ go AllShared = void $ tryIO $ modifyFileMode file $ modef' $
readModes ++
[ ownerWriteMode, groupWriteMode ] ++
if isdir then executeModes else []
- go _ = noop
+ go _ = case modef of
+ Nothing -> noop
+ Just f -> void $ tryIO $
+ modifyFileMode file $ f []
+ modef' = fromMaybe addModes modef
+
+resetAnnexFilePerm :: FilePath -> Annex ()
+resetAnnexFilePerm = resetAnnexPerm False
+
+{- Like setAnnexPerm, but ignores the current mode of the file entirely,
+ - and sets the same mode that the umask would result in when creating a
+ - new file.
+ -
+ - Useful eg, after creating a temporary file with locked down modes,
+ - which is going to be moved to a non-temporary location and needs
+ - usual modes.
+ -}
+resetAnnexPerm :: Bool -> FilePath -> Annex ()
+resetAnnexPerm isdir file = unlessM crippledFileSystem $ do
+ defmode <- liftIO defaultFileMode
+ let modef moremodes _oldmode = addModes moremodes defmode
+ setAnnexPerm' (Just modef) isdir file
{- Gets the appropriate mode to use for creating a file in the annex
- - (other than content files, which are locked down more). -}
+ - (other than content files, which are locked down more). The umask is not
+ - taken into account; this is for use with actions that create the file
+ - and apply the umask automatically. -}
annexFileMode :: Annex FileMode
annexFileMode = withShared $ return . go
where
{- Runs an action like writeFile, writing to a temp file first and
- then moving it into place. The temp file is stored in the same
- directory as the final file to avoid cross-device renames.
+ -
+ - Note that the tmp file will have a file mode that only allows the
+ - current user to access it. The write action can change the mode
+ - to whatever is desired.
-}
viaTmp :: (MonadMask m, MonadIO m) => (FilePath -> v -> m ()) -> FilePath -> v -> m ()
viaTmp a file content = bracketIO setup cleanup use
withTmpFileIn tmpdir template a
{- Runs an action with a tmp file located in the specified directory,
- - then removes the file. -}
+ - then removes the file.
+ -
+ - Note that the tmp file will have a file mode that only allows the
+ - current user to access it.
+ -}
withTmpFileIn :: (MonadIO m, MonadMask m) => FilePath -> Template -> (FilePath -> Handle -> m a) -> m a
withTmpFileIn tmpdir template a = bracket create remove use
where
`withTmpFileIn` also uses openTempFile, and probably its callers do need to
adjust perms if desired since it could be used with a real temp directory.
+> Audited and fixed these. It affected only directory special remote and
+> bittorrent special remote if a download from it were interrupted and then
+> resumed by a different user than the one who started it. --[[Joey]]
+
There are also a couple of other uses of openTempFile, which need to be
audited for this problem. --[[Joey]]
+
+> Checked, all were ok. --[[Joey]]