make viaTmp honor umask
Fixed several cases where files were created without file mode bits that the umask would usually set. This included exports to the directory special remote, torrent files used by the bittorrent special remote, hooks written by git-annex init, and some log files in .git/annex/ Audited all calls, looking for ones that didn't want the umask bits to be set. All such turned out to already set the specific restrictive file mode they wanted.
This commit is contained in:
parent
6361f7c310
commit
6e9a4f50f3
3 changed files with 17 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
{- Temporary files.
|
||||
-
|
||||
- Copyright 2010-2013 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2010-2020 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- License: BSD-2-clause
|
||||
-}
|
||||
|
@ -24,12 +24,17 @@ import System.PosixCompat.Files
|
|||
|
||||
import Utility.Exception
|
||||
import Utility.FileSystemEncoding
|
||||
import Utility.FileMode
|
||||
|
||||
type Template = String
|
||||
|
||||
{- 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.
|
||||
-
|
||||
- While this uses a temp file, the file will end up with the same
|
||||
- mode as it would when using writeFile, unless the writer action changes
|
||||
- it.
|
||||
-}
|
||||
viaTmp :: (MonadMask m, MonadIO m) => (FilePath -> v -> m ()) -> FilePath -> v -> m ()
|
||||
viaTmp a file content = bracketIO setup cleanup use
|
||||
|
@ -43,6 +48,11 @@ viaTmp a file content = bracketIO setup cleanup use
|
|||
_ <- tryIO $ hClose h
|
||||
tryIO $ removeFile tmpfile
|
||||
use (tmpfile, h) = do
|
||||
-- Make mode the same as if the file were created usually,
|
||||
-- not as a temp file. (This may fail on some filesystems
|
||||
-- that don't support file modes well, so ignore
|
||||
-- exceptions.)
|
||||
void $ tryIO $ setFileMode tmpfile =<< defaultFileMode
|
||||
liftIO $ hClose h
|
||||
a tmpfile content
|
||||
liftIO $ rename tmpfile file
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue