From 265cbb0f66881102aa11f73d0cff41c773ddb3a9 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 12 Feb 2016 14:11:25 -0400 Subject: create directory for transfer lock file, and catch perm error Before, the call to mkProgressUpdater created the directory as a side-effect, but since that ignored failure to create it, this led to a "does not exist" exception when the transfer lock file was created, rather than a permissions error. So, make sure the directory exists before trying to lock the file in it. When a PermissionDenied exception is caught, skip making the transfer lock. This lets downloads from readonly remotes happen. If an upload is being tried, and the lock file can't be written due to permissions, then probably the actual transfer will fail for the same reason, so I think it's ok that it continues w/o taking the lock in that case. --- Annex/Transfer.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'Annex') diff --git a/Annex/Transfer.hs b/Annex/Transfer.hs index 805446b75..af9d89f4d 100644 --- a/Annex/Transfer.hs +++ b/Annex/Transfer.hs @@ -91,8 +91,9 @@ runTransfer' ignorelock t file shouldretry transferobserver transferaction = do return v where #ifndef mingw32_HOST_OS - prep tfile mode info = do + prep tfile mode info = catchPermissionDenied (const prepfailed) $ do let lck = transferLockFile tfile + createAnnexDirectory $ takeDirectory lck r <- tryLockExclusive (Just mode) lck case r of Nothing -> return (Nothing, True) @@ -104,8 +105,9 @@ runTransfer' ignorelock t file shouldretry transferobserver transferaction = do , return (Nothing, True) ) #else - prep tfile _mode info = liftIO $ do + prep tfile _mode info = catchPermissionDenied (const prepfailed) liftIO $ do let lck = transferLockFile tfile + createAnnexDirectory $ takeDirectory lck v <- catchMaybeIO $ lockExclusive lck case v of Nothing -> return (Nothing, False) @@ -115,6 +117,8 @@ runTransfer' ignorelock t file shouldretry transferobserver transferaction = do writeTransferInfoFile info tfile return (Just lockhandle, False) #endif + prepfailed = return (Nothing, False) + cleanup _ Nothing = noop cleanup tfile (Just lockhandle) = do let lck = transferLockFile tfile -- cgit v1.2.3