aboutsummaryrefslogtreecommitdiff
path: root/Annex/Locations.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-11-29 13:49:52 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-11-29 13:53:39 -0400
commitb7178922644c813a2cb69c185ca751aa234fa05b (patch)
tree770900f2dbdd269c5224eaf30ad42f0083732697 /Annex/Locations.hs
parent8c07e4dbf7d5145ed6412278c4288e3c405484ed (diff)
add gitAnnexTmpWorkDir and withTmpWorkDir
Needed to run youtube-dl in, but could also be useful for other stuff. The tricky part of this was making the workdir be cleaned up whenever the tmp object file is cleaned up. This commit was sponsored by Ole-Morten Duesund on Patreon.
Diffstat (limited to 'Annex/Locations.hs')
-rw-r--r--Annex/Locations.hs16
1 files changed, 15 insertions, 1 deletions
diff --git a/Annex/Locations.hs b/Annex/Locations.hs
index f86dfc6f4..acae9c079 100644
--- a/Annex/Locations.hs
+++ b/Annex/Locations.hs
@@ -1,6 +1,6 @@
{- git-annex file locations
-
- - Copyright 2010-2015 Joey Hess <id@joeyh.name>
+ - Copyright 2010-2017 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -27,6 +27,7 @@ module Annex.Locations (
gitAnnexTmpMiscDir,
gitAnnexTmpObjectDir,
gitAnnexTmpObjectLocation,
+ gitAnnexTmpWorkDir,
gitAnnexBadDir,
gitAnnexBadLocation,
gitAnnexUnusedLog,
@@ -251,6 +252,19 @@ gitAnnexTmpObjectDir r = addTrailingPathSeparator $ gitAnnexDir r </> "tmp"
gitAnnexTmpObjectLocation :: Key -> Git.Repo -> FilePath
gitAnnexTmpObjectLocation key r = gitAnnexTmpObjectDir r </> keyFile key
+{- Given a temp file such as gitAnnexTmpObjectLocation, makes a name for a
+ - subdirectory in the same location, that can be used as a work area
+ - when receiving the key's content.
+ -
+ - There are ordering requirements for creating these directories;
+ - use Annex.Content.withTmpWorkDir to set them up.
+ -}
+gitAnnexTmpWorkDir :: FilePath -> FilePath
+gitAnnexTmpWorkDir p =
+ let (dir, f) = splitFileName p
+ -- Using a prefix avoids name conflict with any other keys.
+ in dir </> "work." </> f
+
{- .git/annex/bad/ is used for bad files found during fsck -}
gitAnnexBadDir :: Git.Repo -> FilePath
gitAnnexBadDir r = addTrailingPathSeparator $ gitAnnexDir r </> "bad"