convert listImportableContents to throwing exceptions
This commit is contained in:
parent
5d8e4a7c74
commit
e1ac42be77
8 changed files with 27 additions and 27 deletions
|
@ -658,14 +658,14 @@ makeImportMatcher r = load preferredContentKeylessTokens >>= \case
|
||||||
- regardless. (Similar to how git add behaves on gitignored files.)
|
- regardless. (Similar to how git add behaves on gitignored files.)
|
||||||
- This avoids creating a remote tracking branch that, when merged,
|
- This avoids creating a remote tracking branch that, when merged,
|
||||||
- would delete the files.
|
- would delete the files.
|
||||||
|
-
|
||||||
|
- Throws exception if unable to contact the remote.
|
||||||
-}
|
-}
|
||||||
getImportableContents :: Remote -> ImportTreeConfig -> CheckGitIgnore -> FileMatcher Annex -> Annex (Maybe (ImportableContents (ContentIdentifier, ByteSize)))
|
getImportableContents :: Remote -> ImportTreeConfig -> CheckGitIgnore -> FileMatcher Annex -> Annex (ImportableContents (ContentIdentifier, ByteSize))
|
||||||
getImportableContents r importtreeconfig ci matcher =
|
getImportableContents r importtreeconfig ci matcher = do
|
||||||
Remote.listImportableContents (Remote.importActions r) >>= \case
|
importable <- Remote.listImportableContents (Remote.importActions r)
|
||||||
Nothing -> return Nothing
|
|
||||||
Just importable -> do
|
|
||||||
dbhandle <- Export.openDb (Remote.uuid r)
|
dbhandle <- Export.openDb (Remote.uuid r)
|
||||||
Just <$> filterunwanted dbhandle importable
|
filterunwanted dbhandle importable
|
||||||
where
|
where
|
||||||
filterunwanted dbhandle ic = ImportableContents
|
filterunwanted dbhandle ic = ImportableContents
|
||||||
<$> filterM (wanted dbhandle) (importableContents ic)
|
<$> filterM (wanted dbhandle) (importableContents ic)
|
||||||
|
|
|
@ -334,9 +334,9 @@ listContents remote importtreeconfig ci tvar = starting "list" ai si $
|
||||||
listContents' :: Remote -> ImportTreeConfig -> CheckGitIgnore -> (ImportableContents (ContentIdentifier, Remote.ByteSize) -> Annex a) -> Annex a
|
listContents' :: Remote -> ImportTreeConfig -> CheckGitIgnore -> (ImportableContents (ContentIdentifier, Remote.ByteSize) -> Annex a) -> Annex a
|
||||||
listContents' remote importtreeconfig ci a =
|
listContents' remote importtreeconfig ci a =
|
||||||
makeImportMatcher remote >>= \case
|
makeImportMatcher remote >>= \case
|
||||||
Right matcher -> getImportableContents remote importtreeconfig ci matcher >>= \case
|
Right matcher -> tryNonAsync (getImportableContents remote importtreeconfig ci matcher) >>= \case
|
||||||
Just importable -> a importable
|
Right importable -> a importable
|
||||||
Nothing -> giveup $ "Unable to list contents of " ++ Remote.name remote
|
Left e -> giveup $ "Unable to list contents of " ++ Remote.name remote ++ ": " ++ show e
|
||||||
Left err -> giveup $ unwords
|
Left err -> giveup $ unwords
|
||||||
[ "Cannot import from"
|
[ "Cannot import from"
|
||||||
, Remote.name remote
|
, Remote.name remote
|
||||||
|
|
|
@ -286,9 +286,12 @@ renameExportM serial adir _k old new = do
|
||||||
, File newloc
|
, File newloc
|
||||||
]
|
]
|
||||||
|
|
||||||
listImportableContentsM :: AndroidSerial -> AndroidPath -> Annex (Maybe (ImportableContents (ContentIdentifier, ByteSize)))
|
listImportableContentsM :: AndroidSerial -> AndroidPath -> Annex (ImportableContents (ContentIdentifier, ByteSize))
|
||||||
listImportableContentsM serial adir =
|
listImportableContentsM serial adir = adbfind >>= \case
|
||||||
process <$> adbShell serial
|
Just ls -> return $ ImportableContents (mapMaybe mk ls) []
|
||||||
|
Nothing -> giveup "adb find failed"
|
||||||
|
where
|
||||||
|
adbfind = adbShell serial
|
||||||
[ Param "find"
|
[ Param "find"
|
||||||
-- trailing slash is needed, or android's find command
|
-- trailing slash is needed, or android's find command
|
||||||
-- won't recurse into the directory
|
-- won't recurse into the directory
|
||||||
|
@ -298,9 +301,6 @@ listImportableContentsM serial adir =
|
||||||
, Param "-c", Param statformat
|
, Param "-c", Param statformat
|
||||||
, Param "{}", Param "+"
|
, Param "{}", Param "+"
|
||||||
]
|
]
|
||||||
where
|
|
||||||
process Nothing = Nothing
|
|
||||||
process (Just ls) = Just $ ImportableContents (mapMaybe mk ls) []
|
|
||||||
|
|
||||||
statformat = adbStatFormat ++ "\t%n"
|
statformat = adbStatFormat ++ "\t%n"
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ borgLocal = notElem ':'
|
||||||
-- XXX the tree generated by using this does not seem to get grafted into
|
-- XXX the tree generated by using this does not seem to get grafted into
|
||||||
-- the git-annex branch, so would be subject to being lost to GC.
|
-- the git-annex branch, so would be subject to being lost to GC.
|
||||||
-- Is this a general problem affecting importtree too?
|
-- Is this a general problem affecting importtree too?
|
||||||
listImportableContentsM :: UUID -> BorgRepo -> Annex (Maybe (ImportableContents (ContentIdentifier, ByteSize)))
|
listImportableContentsM :: UUID -> BorgRepo -> Annex (ImportableContents (ContentIdentifier, ByteSize))
|
||||||
listImportableContentsM u borgrepo = prompt $ do
|
listImportableContentsM u borgrepo = prompt $ do
|
||||||
imported <- getImported u
|
imported <- getImported u
|
||||||
ls <- withborglist borgrepo "{barchive}{NUL}" $ \as ->
|
ls <- withborglist borgrepo "{barchive}{NUL}" $ \as ->
|
||||||
|
@ -143,7 +143,7 @@ listImportableContentsM u borgrepo = prompt $ do
|
||||||
let archive = borgrepo ++ "::" ++ decodeBS' archivename
|
let archive = borgrepo ++ "::" ++ decodeBS' archivename
|
||||||
in withborglist archive "{size}{NUL}{path}{NUL}" $
|
in withborglist archive "{size}{NUL}{path}{NUL}" $
|
||||||
liftIO . evaluate . force . parsefilelist archivename
|
liftIO . evaluate . force . parsefilelist archivename
|
||||||
return $ Just $ mkimportablecontents ls
|
return $ mkimportablecontents ls
|
||||||
where
|
where
|
||||||
withborglist what format a = do
|
withborglist what format a = do
|
||||||
let p = (proc "borg" ["list", what, "--format", format])
|
let p = (proc "borg" ["list", what, "--format", format])
|
||||||
|
|
|
@ -337,8 +337,8 @@ removeExportLocation topdir loc =
|
||||||
mkExportLocation loc'
|
mkExportLocation loc'
|
||||||
in go (upFrom loc') =<< tryIO (removeDirectory p)
|
in go (upFrom loc') =<< tryIO (removeDirectory p)
|
||||||
|
|
||||||
listImportableContentsM :: RawFilePath -> Annex (Maybe (ImportableContents (ContentIdentifier, ByteSize)))
|
listImportableContentsM :: RawFilePath -> Annex (ImportableContents (ContentIdentifier, ByteSize))
|
||||||
listImportableContentsM dir = catchMaybeIO $ liftIO $ do
|
listImportableContentsM dir = liftIO $ do
|
||||||
l <- dirContentsRecursive (fromRawFilePath dir)
|
l <- dirContentsRecursive (fromRawFilePath dir)
|
||||||
l' <- mapM (go . toRawFilePath) l
|
l' <- mapM (go . toRawFilePath) l
|
||||||
return $ ImportableContents (catMaybes l') []
|
return $ ImportableContents (catMaybes l') []
|
||||||
|
|
|
@ -54,7 +54,7 @@ instance HasImportUnsupported (ParsedRemoteConfig -> RemoteGitConfig -> Annex Bo
|
||||||
|
|
||||||
instance HasImportUnsupported (ImportActions Annex) where
|
instance HasImportUnsupported (ImportActions Annex) where
|
||||||
importUnsupported = ImportActions
|
importUnsupported = ImportActions
|
||||||
{ listImportableContents = return Nothing
|
{ listImportableContents = nope
|
||||||
, importKey = Nothing
|
, importKey = Nothing
|
||||||
, retrieveExportWithContentIdentifier = nope
|
, retrieveExportWithContentIdentifier = nope
|
||||||
, storeExportWithContentIdentifier = nope
|
, storeExportWithContentIdentifier = nope
|
||||||
|
|
|
@ -550,13 +550,11 @@ renameExportS3 hv r rs info k src dest = Just <$> go
|
||||||
srcobject = T.pack $ bucketExportLocation info src
|
srcobject = T.pack $ bucketExportLocation info src
|
||||||
dstobject = T.pack $ bucketExportLocation info dest
|
dstobject = T.pack $ bucketExportLocation info dest
|
||||||
|
|
||||||
listImportableContentsS3 :: S3HandleVar -> Remote -> S3Info -> Annex (Maybe (ImportableContents (ContentIdentifier, ByteSize)))
|
listImportableContentsS3 :: S3HandleVar -> Remote -> S3Info -> Annex (ImportableContents (ContentIdentifier, ByteSize))
|
||||||
listImportableContentsS3 hv r info =
|
listImportableContentsS3 hv r info =
|
||||||
withS3Handle hv $ \case
|
withS3Handle hv $ \case
|
||||||
Nothing -> do
|
Nothing -> giveup $ needS3Creds (uuid r)
|
||||||
warning $ needS3Creds (uuid r)
|
Just h -> liftIO $ runResourceT $
|
||||||
return Nothing
|
|
||||||
Just h -> catchMaybeIO $ liftIO $ runResourceT $
|
|
||||||
extractFromResourceT =<< startlist h
|
extractFromResourceT =<< startlist h
|
||||||
where
|
where
|
||||||
startlist h
|
startlist h
|
||||||
|
|
|
@ -281,7 +281,9 @@ data ImportActions a = ImportActions
|
||||||
--
|
--
|
||||||
-- May also find old versions of files that are still stored in the
|
-- May also find old versions of files that are still stored in the
|
||||||
-- remote.
|
-- remote.
|
||||||
{ listImportableContents :: a (Maybe (ImportableContents (ContentIdentifier, ByteSize)))
|
--
|
||||||
|
-- Throws exception on failure to access the remote.
|
||||||
|
{ listImportableContents :: a (ImportableContents (ContentIdentifier, ByteSize))
|
||||||
-- Generates a Key (of any type) for the file stored on the
|
-- Generates a Key (of any type) for the file stored on the
|
||||||
-- remote at the ImportLocation. Does not download the file
|
-- remote at the ImportLocation. Does not download the file
|
||||||
-- from the remote.
|
-- from the remote.
|
||||||
|
|
Loading…
Reference in a new issue