drop webdav compatability with the directory special remote etc

The benefit of using a compatable directory structure does not outweigh the
cost in complexity of handling the multiple locations content can be stored
in directory special remotes. And this also allows doing away with the parent
directories, which can't be made unwritable in DAV, so have no benefit
there. This will save 2 http calls per file store.

But, kept the directory hashing, just in case.
This commit is contained in:
Joey Hess 2012-11-16 00:42:33 -04:00
parent a4b86c63d6
commit bb28c6114a
4 changed files with 47 additions and 55 deletions

View file

@ -11,6 +11,7 @@ module Locations (
keyPaths, keyPaths,
gitAnnexLocation, gitAnnexLocation,
annexLocations, annexLocations,
annexLocation,
gitAnnexDir, gitAnnexDir,
gitAnnexObjectDir, gitAnnexObjectDir,
gitAnnexTmpDir, gitAnnexTmpDir,

View file

@ -81,15 +81,14 @@ webdavSetup u c = do
setRemoteCredPair c (davCreds u) setRemoteCredPair c (davCreds u)
store :: Remote -> Key -> AssociatedFile -> MeterUpdate -> Annex Bool store :: Remote -> Key -> AssociatedFile -> MeterUpdate -> Annex Bool
store r k _f _p = do store r k _f _p = davAction r False $ \(baseurl, user, pass) -> do
let url = davLocation baseurl k
liftIO $ davMkdir (urlParent url) user pass
f <- inRepo $ gitAnnexLocation k f <- inRepo $ gitAnnexLocation k
davAction r False $ \(baseurl, user, pass) -> liftIO $ do b <- liftIO $ L.readFile f
let url = Prelude.head $ davLocations baseurl k v <- liftIO $ catchMaybeHttp $ putContentAndProps url user pass
davMkdir (urlParent url) user pass (noProps, (contentType, b))
b <- L.readFile f return $ isJust v
v <- catchMaybeHttp $ putContentAndProps url user pass
(noProps, (contentType, b))
return $ isJust v
storeEncrypted :: Remote -> (Cipher, Key) -> Key -> MeterUpdate -> Annex Bool storeEncrypted :: Remote -> (Cipher, Key) -> Key -> MeterUpdate -> Annex Bool
storeEncrypted r (cipher, enck) k _p = davAction r False $ \creds -> liftIO $ do storeEncrypted r (cipher, enck) k _p = davAction r False $ \creds -> liftIO $ do
@ -98,14 +97,13 @@ storeEncrypted r (cipher, enck) k _p = davAction r False $ \creds -> liftIO $ do
retrieve :: Remote -> Key -> AssociatedFile -> FilePath -> Annex Bool retrieve :: Remote -> Key -> AssociatedFile -> FilePath -> Annex Bool
retrieve r k _f d = davAction r False $ liftIO . go retrieve r k _f d = davAction r False $ liftIO . go
where where
go (baseurl, user, pass) = get $ davLocations baseurl k go (baseurl, user, pass) = do
where let url = davLocation baseurl k
get [] = return False maybe (return False) save
get (u:urls) = maybe (get urls) save =<< catchMaybeHttp (getPropsAndContent url user pass)
=<< catchMaybeHttp (getPropsAndContent u user pass) save (_, (_, b)) = do
save (_, (_, b)) = do L.writeFile d b
L.writeFile d b return True
return True
retrieveCheap :: Remote -> Key -> FilePath -> Annex Bool retrieveCheap :: Remote -> Key -> FilePath -> Annex Bool
retrieveCheap _ _ _ = return False retrieveCheap _ _ _ = return False
@ -117,39 +115,24 @@ retrieveEncrypted r (cipher, enck) _ f = davAction r False $ \creds -> do
remove :: Remote -> Key -> Annex Bool remove :: Remote -> Key -> Annex Bool
remove r k = davAction r False $ liftIO . go remove r k = davAction r False $ liftIO . go
where where
go (baseurl, user, pass) = delone $ davLocations baseurl k go (baseurl, user, pass) = do
where let url = davLocation baseurl k
delone [] = return False isJust <$> catchMaybeHttp (deleteContent url user pass)
delone (u:urls) = maybe (delone urls) (const $ return True)
=<< catchMaybeHttp (deletedir u)
{- Rather than deleting first the file, and then its
- immediate parent directory (to clean up), delete the
- parent directory, along with all its contents in a
- single recursive DAV call.
-
- The file is the only thing we keep in there, and this
- is faster. -}
deletedir u = deleteContent (urlParent u) user pass
checkPresent :: Remote -> Key -> Annex (Either String Bool) checkPresent :: Remote -> Key -> Annex (Either String Bool)
checkPresent r k = davAction r noconn go checkPresent r k = davAction r noconn $ \(baseurl, user, pass) -> do
showAction $ "checking " ++ name r
let url = davLocation baseurl k
v <- liftIO $ catchHttp $ getProps url user pass
case v of
Right _ -> return $ Right True
Left (Left (StatusCodeException status _))
| statusCode status == statusCode notFound404 -> return $ Right False
| otherwise -> return $ Left $ show $ statusMessage status
Left (Left httpexception) -> return $ Left $ show httpexception
Left (Right ioexception) -> return $ Left $ show ioexception
where where
noconn = Left $ error $ name r ++ " not configured" noconn = Left $ error $ name r ++ " not configured"
go (baseurl, user, pass) = do
showAction $ "checking " ++ name r
liftIO $ check $ davLocations baseurl k
where
check [] = return $ Right False
check (u:urls) = do
v <- catchHttp $ getProps u user pass
case v of
Right _ -> return $ Right True
Left (Left (StatusCodeException status _))
| statusCode status == statusCode notFound404 -> check urls
| otherwise -> return $ Left $ show $ statusMessage status
Left (Left httpexception) -> return $ Left $ show httpexception
Left (Right ioexception) -> return $ Left $ show ioexception
davAction :: Remote -> a -> ((DavUrl, DavUser, DavPass) -> Annex a) -> Annex a davAction :: Remote -> a -> ((DavUrl, DavUser, DavPass) -> Annex a) -> Annex a
davAction r unconfigured action = case config r of davAction r unconfigured action = case config r of
@ -167,12 +150,9 @@ toDavUser = B8.fromString
toDavPass :: String -> DavPass toDavPass :: String -> DavPass
toDavPass = B8.fromString toDavPass = B8.fromString
{- All possibile locations to try to access a given Key. {- The location to use to store a Key. -}
- davLocation :: DavUrl -> Key -> DavUrl
- This is intentially the same as the directory special remote uses, to davLocation baseurl k = davUrl baseurl $ hashDirLower k </> keyFile k
- allow interoperability. -}
davLocations :: DavUrl -> Key -> [DavUrl]
davLocations baseurl k = map (davUrl baseurl) (keyPaths k)
davUrl :: DavUrl -> FilePath -> DavUrl davUrl :: DavUrl -> FilePath -> DavUrl
davUrl baseurl file = baseurl </> file davUrl baseurl file = baseurl </> file

View file

@ -28,10 +28,10 @@ the webdav remote.
WebDAV. For use when the WebDAV server has file size WebDAV. For use when the WebDAV server has file size
limitations. The default is to never chunk files. limitations. The default is to never chunk files.
The value can use specified using any commonly used units. The value can use specified using any commonly used units.
Example: `chunksize=100 megabytes` Example: `chunksize=75 megabytes`
Note that enabling chunking on an existing remote with non-chunked Note that enabling chunking on an existing remote with non-chunked
files is not recommended. files is not recommended.
Setup example: Setup example:
# WEBDAV_USERNAME=joey@kitenet.net WEBDAV_PASSWORD=xxxxxxx git annex initremote box.com type=webdav url=https://www.box.com/dav/git-annex encryption=joey@kitenet.net # WEBDAV_USERNAME=joey@kitenet.net WEBDAV_PASSWORD=xxxxxxx git annex initremote box.com type=webdav url=https://www.box.com/dav/git-annex chunksize=75mb encryption=joey@kitenet.net

View file

@ -2,8 +2,19 @@
for providing 50 gb of free storage if you sign up with its Android client. for providing 50 gb of free storage if you sign up with its Android client.
(Or a few gb free otherwise.) (Or a few gb free otherwise.)
With a little setup, git-annex can use Box as a git-annex can use Box as a [[special remote|special_remotes]].
[[special remote|special_remotes]]. Recent versions of git-annex make this very easy to set up:
WEBDAV_USERNAME=you@example.com WEBDAV_PASSWORD=xxxxxxx git annex initremote box.com type=webdav url=https://www.box.com/dav/git-annex chunksize=75mb encryption=you@example.com
Note the use of chunksize; Box has a 100 mb maximum file size, and this
breaks up large files into chunks before that limit is reached.
# old davfs2 method
This method is deprecated, but still documented here just in case.
Note that the files stored using this method cannot reliably be retreived
using the webdav special remote.
## davfs2 setup ## davfs2 setup