use openTempFile from file-io
And follow-on changes. Note that relatedTemplate was changed to operate on a RawFilePath, and so when it counts the length, it is now the number of bytes, not the number of code points. This will just make it truncate shorter strings in some cases, the truncation is still unicode aware. When not building with the OsPath flag, toOsPath . fromRawFilePath and fromRawFilePath . fromOsPath do extra conversions back and forth between String and ByteString. That overhead could be avoided, but that's the non-optimised build mode, so didn't bother. Sponsored-by: unqueued
This commit is contained in:
parent
1faa3af9cd
commit
793ddecd4b
46 changed files with 235 additions and 178 deletions
|
@ -312,12 +312,12 @@ performExport r srcrs db ek af contentsha loc allfilledvar = do
|
|||
sent <- tryNonAsync $ if not (isGitShaKey ek)
|
||||
then tryrenameannexobject $ sendannexobject
|
||||
-- Sending a non-annexed file.
|
||||
else withTmpFile "export" $ \tmp h -> do
|
||||
else withTmpFile (toOsPath "export") $ \tmp h -> do
|
||||
b <- catObject contentsha
|
||||
liftIO $ L.hPut h b
|
||||
liftIO $ hClose h
|
||||
Remote.action $
|
||||
storer tmp ek loc nullMeterUpdate
|
||||
storer (fromRawFilePath (fromOsPath tmp)) ek loc nullMeterUpdate
|
||||
let failedsend = liftIO $ modifyMVar_ allfilledvar (pure . const (AllFilled False))
|
||||
case sent of
|
||||
Right True -> next $ cleanupExport r db ek loc True
|
||||
|
|
|
@ -158,10 +158,11 @@ getFeed o url st =
|
|||
| scrapeOption o = scrape
|
||||
| otherwise = get
|
||||
|
||||
get = withTmpFile "feed" $ \tmpf h -> do
|
||||
get = withTmpFile (toOsPath "feed") $ \tmpf h -> do
|
||||
let tmpf' = fromRawFilePath $ fromOsPath tmpf
|
||||
liftIO $ hClose h
|
||||
ifM (downloadFeed url tmpf)
|
||||
( parse tmpf
|
||||
ifM (downloadFeed url tmpf')
|
||||
( parse tmpf'
|
||||
, do
|
||||
recordfail
|
||||
next $ feedProblem url
|
||||
|
|
|
@ -130,7 +130,7 @@ send ups fs = do
|
|||
-- the names of keys, and would have to be copied, which is too
|
||||
-- expensive.
|
||||
starting "sending files" (ActionItemOther Nothing) (SeekInput []) $
|
||||
withTmpFile "send" $ \t h -> do
|
||||
withTmpFile (toOsPath "send") $ \t h -> do
|
||||
let ww = WarnUnmatchLsFiles "multicast"
|
||||
(fs', cleanup) <- seekHelper id ww LsFiles.inRepo
|
||||
=<< workTreeItems ww fs
|
||||
|
@ -163,7 +163,7 @@ send ups fs = do
|
|||
-- only allow clients on the authlist
|
||||
, Param "-H", Param ("@"++authlist)
|
||||
-- pass in list of files to send
|
||||
, Param "-i", File t
|
||||
, Param "-i", File (fromRawFilePath (fromOsPath t))
|
||||
] ++ ups
|
||||
liftIO (boolSystem "uftp" ps) >>= showEndResult
|
||||
next $ return True
|
||||
|
@ -178,7 +178,7 @@ receive ups = starting "receiving multicast files" ai si $ do
|
|||
(callback, environ, statush) <- liftIO multicastCallbackEnv
|
||||
tmpobjdir <- fromRepo gitAnnexTmpObjectDir
|
||||
createAnnexDirectory tmpobjdir
|
||||
withTmpDirIn (fromRawFilePath tmpobjdir) "multicast" $ \tmpdir -> withAuthList $ \authlist -> do
|
||||
withTmpDirIn (fromRawFilePath tmpobjdir) (toOsPath "multicast") $ \tmpdir -> withAuthList $ \authlist -> do
|
||||
abstmpdir <- liftIO $ absPath (toRawFilePath tmpdir)
|
||||
abscallback <- liftIO $ searchPath callback
|
||||
let ps =
|
||||
|
@ -245,10 +245,10 @@ uftpUID u = "0x" ++ (take 8 $ show $ sha2_256 $ B8.fromString (fromUUID u))
|
|||
withAuthList :: (FilePath -> Annex a) -> Annex a
|
||||
withAuthList a = do
|
||||
m <- knownFingerPrints
|
||||
withTmpFile "authlist" $ \t h -> do
|
||||
withTmpFile (toOsPath "authlist") $ \t h -> do
|
||||
liftIO $ hPutStr h (genAuthList m)
|
||||
liftIO $ hClose h
|
||||
a t
|
||||
a (fromRawFilePath (fromOsPath t))
|
||||
|
||||
genAuthList :: M.Map UUID Fingerprint -> String
|
||||
genAuthList = unlines . map fmt . M.toList
|
||||
|
|
|
@ -220,7 +220,7 @@ wormholePairing remotename ouraddrs ui = do
|
|||
-- files. Permissions of received files may allow others
|
||||
-- to read them. So, set up a temp directory that only
|
||||
-- we can read.
|
||||
withTmpDir "pair" $ \tmp -> do
|
||||
withTmpDir (toOsPath "pair") $ \tmp -> do
|
||||
liftIO $ void $ tryIO $ modifyFileMode (toRawFilePath tmp) $
|
||||
removeModes otherGroupModes
|
||||
let sendf = tmp </> "send"
|
||||
|
|
|
@ -355,11 +355,11 @@ testExportTree runannex mkr mkk1 mkk2 =
|
|||
storeexport ea k = do
|
||||
loc <- fromRawFilePath <$> Annex.calcRepo (gitAnnexLocation k)
|
||||
Remote.storeExport ea loc k testexportlocation nullMeterUpdate
|
||||
retrieveexport ea k = withTmpFile "exported" $ \tmp h -> do
|
||||
retrieveexport ea k = withTmpFile (toOsPath "exported") $ \tmp h -> do
|
||||
liftIO $ hClose h
|
||||
tryNonAsync (Remote.retrieveExport ea k testexportlocation tmp nullMeterUpdate) >>= \case
|
||||
tryNonAsync (Remote.retrieveExport ea k testexportlocation (fromRawFilePath (fromOsPath tmp)) nullMeterUpdate) >>= \case
|
||||
Left _ -> return False
|
||||
Right v -> verifyKeyContentPostRetrieval RetrievalAllKeysSecure AlwaysVerify v k (toRawFilePath tmp)
|
||||
Right v -> verifyKeyContentPostRetrieval RetrievalAllKeysSecure AlwaysVerify v k (fromOsPath tmp)
|
||||
checkpresentexport ea k = Remote.checkPresentExport ea k testexportlocation
|
||||
removeexport ea k = Remote.removeExport ea k testexportlocation
|
||||
removeexportdirectory ea = case Remote.removeExportDirectory ea of
|
||||
|
@ -429,21 +429,21 @@ keySizes base fast = filter want
|
|||
| otherwise = sz > 0
|
||||
|
||||
randKey :: Int -> Annex Key
|
||||
randKey sz = withTmpFile "randkey" $ \f h -> do
|
||||
randKey sz = withTmpFile (toOsPath "randkey") $ \f h -> do
|
||||
gen <- liftIO (newGenIO :: IO SystemRandom)
|
||||
case genBytes sz gen of
|
||||
Left e -> giveup $ "failed to generate random key: " ++ show e
|
||||
Right (rand, _) -> liftIO $ B.hPut h rand
|
||||
liftIO $ hClose h
|
||||
let ks = KeySource
|
||||
{ keyFilename = toRawFilePath f
|
||||
, contentLocation = toRawFilePath f
|
||||
{ keyFilename = fromOsPath f
|
||||
, contentLocation = fromOsPath f
|
||||
, inodeCache = Nothing
|
||||
}
|
||||
k <- case Types.Backend.genKey Backend.Hash.testKeyBackend of
|
||||
Just a -> a ks nullMeterUpdate
|
||||
Nothing -> giveup "failed to generate random key (backend problem)"
|
||||
_ <- moveAnnex k (AssociatedFile Nothing) (toRawFilePath f)
|
||||
_ <- moveAnnex k (AssociatedFile Nothing) (fromOsPath f)
|
||||
return k
|
||||
|
||||
getReadonlyKey :: Remote -> RawFilePath -> Annex Key
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue