assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
{- git-annex assistant unused file preferences
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2014 Joey Hess <id@joeyh.name>
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE QuasiQuotes, TemplateHaskell, OverloadedStrings #-}
|
|
|
|
|
|
|
|
module Assistant.WebApp.Configurators.Unused where
|
|
|
|
|
|
|
|
import Assistant.WebApp.Common
|
|
|
|
import qualified Annex
|
2014-01-23 19:09:43 +00:00
|
|
|
import Utility.HumanTime
|
|
|
|
import Assistant.Unused
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
import Config
|
|
|
|
import Git.Config
|
2014-01-23 19:09:43 +00:00
|
|
|
import Logs.Unused
|
|
|
|
import Utility.Tense
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
|
2014-01-23 19:09:43 +00:00
|
|
|
import qualified Text.Hamlet as Hamlet
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
|
2014-01-23 19:09:43 +00:00
|
|
|
data UnusedForm = UnusedForm
|
|
|
|
{ enableExpire :: Bool
|
|
|
|
, expireWhen :: Integer
|
|
|
|
}
|
|
|
|
|
|
|
|
unusedForm :: UnusedForm -> Hamlet.Html -> MkMForm UnusedForm
|
|
|
|
unusedForm def msg = do
|
2014-04-18 00:07:09 +00:00
|
|
|
(enableRes, enableView) <- mreq (selectFieldList enabledisable) (bfs "")
|
2014-01-23 19:09:43 +00:00
|
|
|
(Just $ enableExpire def)
|
2014-04-18 00:07:09 +00:00
|
|
|
(whenRes, whenView) <- mreq intField (bfs "")
|
2014-01-23 19:09:43 +00:00
|
|
|
(Just $ expireWhen def)
|
|
|
|
let form = do
|
|
|
|
webAppFormAuthToken
|
|
|
|
$(widgetFile "configurators/unused/form")
|
|
|
|
return (UnusedForm <$> enableRes <*> whenRes, form)
|
|
|
|
where
|
|
|
|
enabledisable :: [(Text, Bool)]
|
|
|
|
enabledisable = [("Disable expiry", False), ("Enable expiry", True)]
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
|
2014-01-23 19:09:43 +00:00
|
|
|
getConfigUnusedR :: Handler Html
|
|
|
|
getConfigUnusedR = postConfigUnusedR
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
postConfigUnusedR :: Handler Html
|
2014-01-23 19:09:43 +00:00
|
|
|
postConfigUnusedR = page "Unused files" (Just Configuration) $ do
|
|
|
|
current <- liftAnnex getUnused
|
|
|
|
((res, form), enctype) <- liftH $ runFormPostNoToken $ unusedForm current
|
|
|
|
case res of
|
|
|
|
FormSuccess new -> liftH $ do
|
|
|
|
liftAnnex $ storeUnused new
|
|
|
|
redirect ConfigurationR
|
|
|
|
_ -> do
|
|
|
|
munuseddesc <- liftAssistant describeUnused
|
|
|
|
ts <- liftAnnex $ dateUnusedLog ""
|
|
|
|
mlastchecked <- case ts of
|
|
|
|
Nothing -> pure Nothing
|
|
|
|
Just t -> Just <$> liftIO (durationSince t)
|
|
|
|
$(widgetFile "configurators/unused")
|
|
|
|
|
|
|
|
getUnused :: Annex UnusedForm
|
|
|
|
getUnused = convert . annexExpireUnused <$> Annex.getGitConfig
|
|
|
|
where
|
|
|
|
convert Nothing = noexpire
|
|
|
|
convert (Just Nothing) = noexpire
|
|
|
|
convert (Just (Just n)) = UnusedForm True $ durationToDays n
|
|
|
|
|
|
|
|
-- The 7 is so that, if they enable expiry, they have to change
|
|
|
|
-- it to get faster than a week.
|
|
|
|
noexpire = UnusedForm False 7
|
|
|
|
|
|
|
|
storeUnused :: UnusedForm -> Annex ()
|
|
|
|
storeUnused f = setConfig (annexConfig "expireunused") $
|
|
|
|
if not (enableExpire f) || expireWhen f < 0
|
|
|
|
then boolConfig False
|
|
|
|
else fromDuration $ daysToDuration $ expireWhen f
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
|
2014-01-23 19:09:43 +00:00
|
|
|
getCleanupUnusedR :: Handler Html
|
|
|
|
getCleanupUnusedR = do
|
|
|
|
liftAssistant $ expireUnused Nothing
|
|
|
|
redirect ConfigUnusedR
|