S3: Avoid writing or checking the uuid file in the S3 bucket when importtree=yes or exporttree=yes

It does not make sense for either; importing from an existing bucket should
not write to it. And the user may not have write access at all. And exporting to
a bucket should not write other files.

Also this prevents the uuid file being imported after being written.

Sponsored-by: Dartmouth College's DANDI project
This commit is contained in:
Joey Hess 2022-07-14 15:05:51 -04:00
parent c3df38dd15
commit 093ad89ead
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 17 additions and 9 deletions

View file

@ -15,6 +15,8 @@ git-annex (10.20220625) UNRELEASED; urgency=medium
This may need to be enabled for old android devices that used to work This may need to be enabled for old android devices that used to work
without it being set, since version 10.20220222 started using without it being set, since version 10.20220222 started using
find -printf. find -printf.
* S3: Avoid writing or checking the uuid file in the S3 bucket when
importtree=yes or exporttree=yes.
-- Joey Hess <id@joeyh.name> Tue, 28 Jun 2022 14:49:17 -0400 -- Joey Hess <id@joeyh.name> Tue, 28 Jun 2022 14:49:17 -0400

View file

@ -777,9 +777,11 @@ genBucket c gc u = do
- -
- Note that IA buckets can only created by having a file - Note that IA buckets can only created by having a file
- stored in them. So this also takes care of that. - stored in them. So this also takes care of that.
-
- Not done for import/export buckets.
-} -}
writeUUIDFile :: ParsedRemoteConfig -> UUID -> S3Info -> S3Handle -> Annex () writeUUIDFile :: ParsedRemoteConfig -> UUID -> S3Info -> S3Handle -> Annex ()
writeUUIDFile c u info h = do writeUUIDFile c u info h = unless (exportTree c || importTree c) $ do
v <- checkUUIDFile c u info h v <- checkUUIDFile c u info h
case v of case v of
Right True -> noop Right True -> noop
@ -794,9 +796,13 @@ writeUUIDFile c u info h = do
mkobject = putObject info file (RequestBodyLBS uuidb) mkobject = putObject info file (RequestBodyLBS uuidb)
{- Checks if the UUID file exists in the bucket {- Checks if the UUID file exists in the bucket
- and has the specified UUID already. -} - and has the specified UUID already.
-
- Not done for import/export buckets. -}
checkUUIDFile :: ParsedRemoteConfig -> UUID -> S3Info -> S3Handle -> Annex (Either SomeException Bool) checkUUIDFile :: ParsedRemoteConfig -> UUID -> S3Info -> S3Handle -> Annex (Either SomeException Bool)
checkUUIDFile c u info h = tryNonAsync $ liftIO $ runResourceT $ do checkUUIDFile c u info h
| exportTree c || importTree c = pure (Right False)
| otherwise = tryNonAsync $ liftIO $ runResourceT $ do
resp <- tryS3 $ sendS3Handle h (S3.getObject (bucket info) file) resp <- tryS3 $ sendS3Handle h (S3.getObject (bucket info) file)
case resp of case resp of
Left _ -> return False Left _ -> return False