2012-06-13 21:54:23 +00:00
|
|
|
{- git-annex assistant sanity checker
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2012, 2013 Joey Hess <id@joeyh.name>
|
2012-06-23 05:20:40 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2012-06-13 21:54:23 +00:00
|
|
|
-}
|
|
|
|
|
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
|
|
|
{-# LANGUAGE CPP #-}
|
2019-01-11 20:34:04 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
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
|
|
|
|
2012-06-25 20:10:10 +00:00
|
|
|
module Assistant.Threads.SanityChecker (
|
assistant: Detect stale git lock files at startup time, and remove them.
Extends the index.lock handling to other git lock files. I surveyed
all lock files used by git, and found more than I expected. All are
handled the same in git; it leaves them open while doing the operation,
possibly writing the new file content to the lock file, and then closes
them when done.
The gc.pid file is excluded because it won't affect the normal operation
of the assistant, and waiting for a gc to finish on startup wouldn't be
good.
All threads except the webapp thread wait on the new startup sanity checker
thread to complete, so they won't try to do things with git that fail
due to stale lock files. The webapp thread mostly avoids doing that kind of
thing itself. A few configurators might fail on lock files, but only if the
user is explicitly trying to run them. The webapp needs to start
immediately when the user has opened it, even if there are stale lock
files.
Arranging for the threads to wait on the startup sanity checker was a bit
of a bear. Have to get all the NotificationHandles set up before the
startup sanity checker runs, or they won't see its signal. Perhaps
the NotificationBroadcaster is not the best interface to have used for
this. Oh well, it works.
This commit was sponsored by Michael Jakl
2013-10-05 21:02:11 +00:00
|
|
|
sanityCheckerStartupThread,
|
2013-03-01 17:30:48 +00:00
|
|
|
sanityCheckerDailyThread,
|
|
|
|
sanityCheckerHourlyThread
|
2012-06-13 21:54:23 +00:00
|
|
|
) where
|
|
|
|
|
2012-07-20 23:29:59 +00:00
|
|
|
import Assistant.Common
|
2012-06-13 21:54:23 +00:00
|
|
|
import Assistant.DaemonStatus
|
2012-07-29 21:53:18 +00:00
|
|
|
import Assistant.Alert
|
2013-10-29 17:41:44 +00:00
|
|
|
import Assistant.Repair
|
2014-01-23 20:51:16 +00:00
|
|
|
import Assistant.Drop
|
2013-12-21 00:58:36 +00:00
|
|
|
import Assistant.Ssh
|
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 Assistant.TransferQueue
|
|
|
|
import Assistant.Types.UrlRenderer
|
2014-09-15 18:45:37 +00:00
|
|
|
import Assistant.Restart
|
2014-01-14 21:10:30 +00:00
|
|
|
import qualified Annex.Branch
|
2014-09-15 18:45:37 +00:00
|
|
|
import qualified Git
|
2012-07-20 23:29:59 +00:00
|
|
|
import qualified Git.LsFiles
|
2014-07-04 16:18:49 +00:00
|
|
|
import qualified Git.Command.Batch
|
2013-03-03 18:07:13 +00:00
|
|
|
import qualified Git.Config
|
2012-06-13 21:54:23 +00:00
|
|
|
import Utility.ThreadScheduler
|
2012-06-25 20:10:10 +00:00
|
|
|
import qualified Assistant.Threads.Watcher as Watcher
|
2013-06-21 17:29:42 +00:00
|
|
|
import Utility.Batch
|
assistant: Detect stale git lock files at startup time, and remove them.
Extends the index.lock handling to other git lock files. I surveyed
all lock files used by git, and found more than I expected. All are
handled the same in git; it leaves them open while doing the operation,
possibly writing the new file content to the lock file, and then closes
them when done.
The gc.pid file is excluded because it won't affect the normal operation
of the assistant, and waiting for a gc to finish on startup wouldn't be
good.
All threads except the webapp thread wait on the new startup sanity checker
thread to complete, so they won't try to do things with git that fail
due to stale lock files. The webapp thread mostly avoids doing that kind of
thing itself. A few configurators might fail on lock files, but only if the
user is explicitly trying to run them. The webapp needs to start
immediately when the user has opened it, even if there are stale lock
files.
Arranging for the threads to wait on the startup sanity checker was a bit
of a bear. Have to get all the NotificationHandles set up before the
startup sanity checker runs, or they won't see its signal. Perhaps
the NotificationBroadcaster is not the best interface to have used for
this. Oh well, it works.
This commit was sponsored by Michael Jakl
2013-10-05 21:02:11 +00:00
|
|
|
import Utility.NotificationBroadcaster
|
2013-10-26 16:42:58 +00:00
|
|
|
import Utility.HumanTime
|
2014-01-23 19:09:43 +00:00
|
|
|
import Utility.Tense
|
2013-11-13 18:27:17 +00:00
|
|
|
import Git.Repair
|
2013-11-30 18:29:11 +00:00
|
|
|
import Git.Index
|
2014-01-23 19:09:43 +00:00
|
|
|
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 Logs.Unused
|
2016-08-03 16:37:12 +00:00
|
|
|
import Types.Transfer
|
2015-02-28 21:23:13 +00:00
|
|
|
import Annex.Path
|
2019-01-17 19:40:44 +00:00
|
|
|
import Annex.Tmp
|
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 qualified Annex
|
2020-11-06 18:10:58 +00:00
|
|
|
import qualified Utility.RawFilePath as R
|
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
|
|
|
#ifdef WITH_WEBAPP
|
|
|
|
import Assistant.WebApp.Types
|
|
|
|
#endif
|
2014-02-25 18:09:39 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
|
|
|
import Utility.LogFile
|
2014-12-29 21:25:59 +00:00
|
|
|
import Utility.DiskFree
|
2014-02-25 18:09:39 +00:00
|
|
|
#endif
|
2012-06-13 21:54:23 +00:00
|
|
|
|
|
|
|
import Data.Time.Clock.POSIX
|
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 qualified Data.Text as T
|
2023-03-01 19:55:58 +00:00
|
|
|
import System.PosixCompat.Files (statusChangeTime, isSymbolicLink)
|
2012-06-13 21:54:23 +00:00
|
|
|
|
assistant: Detect stale git lock files at startup time, and remove them.
Extends the index.lock handling to other git lock files. I surveyed
all lock files used by git, and found more than I expected. All are
handled the same in git; it leaves them open while doing the operation,
possibly writing the new file content to the lock file, and then closes
them when done.
The gc.pid file is excluded because it won't affect the normal operation
of the assistant, and waiting for a gc to finish on startup wouldn't be
good.
All threads except the webapp thread wait on the new startup sanity checker
thread to complete, so they won't try to do things with git that fail
due to stale lock files. The webapp thread mostly avoids doing that kind of
thing itself. A few configurators might fail on lock files, but only if the
user is explicitly trying to run them. The webapp needs to start
immediately when the user has opened it, even if there are stale lock
files.
Arranging for the threads to wait on the startup sanity checker was a bit
of a bear. Have to get all the NotificationHandles set up before the
startup sanity checker runs, or they won't see its signal. Perhaps
the NotificationBroadcaster is not the best interface to have used for
this. Oh well, it works.
This commit was sponsored by Michael Jakl
2013-10-05 21:02:11 +00:00
|
|
|
{- This thread runs once at startup, and most other threads wait for it
|
|
|
|
- to finish. (However, the webapp thread does not, to prevent the UI
|
|
|
|
- being nonresponsive.) -}
|
2013-10-26 16:42:58 +00:00
|
|
|
sanityCheckerStartupThread :: Maybe Duration -> NamedThread
|
|
|
|
sanityCheckerStartupThread startupdelay = namedThreadUnchecked "SanityCheckerStartup" $ do
|
2013-10-29 20:48:06 +00:00
|
|
|
{- Stale git locks can prevent commits from happening, etc. -}
|
2013-10-29 18:22:56 +00:00
|
|
|
void $ repairStaleGitLocks =<< liftAnnex gitRepo
|
2013-10-26 16:42:58 +00:00
|
|
|
|
2013-11-13 18:27:17 +00:00
|
|
|
{- A corrupt index file can prevent the assistant from working at
|
|
|
|
- all, so detect and repair. -}
|
2013-12-10 19:40:01 +00:00
|
|
|
ifM (not <$> liftAnnex (inRepo checkIndexFast))
|
2013-11-13 18:39:26 +00:00
|
|
|
( do
|
2021-04-05 17:40:31 +00:00
|
|
|
debug ["corrupt index file found at startup; removing and restaging"]
|
2020-11-06 18:10:58 +00:00
|
|
|
liftAnnex $ inRepo $ removeWhenExistsWith R.removeLink . indexFile
|
2013-11-13 18:39:26 +00:00
|
|
|
{- Normally the startup scan avoids re-staging files,
|
|
|
|
- but with the index deleted, everything needs to be
|
|
|
|
- restaged. -}
|
|
|
|
modifyDaemonStatus_ $ \s -> s { forceRestage = True }
|
|
|
|
, whenM (liftAnnex $ inRepo missingIndex) $ do
|
|
|
|
debug ["no index file; restaging"]
|
|
|
|
modifyDaemonStatus_ $ \s -> s { forceRestage = True }
|
|
|
|
)
|
2014-01-14 21:10:30 +00:00
|
|
|
{- If the git-annex index file is corrupt, it's ok to remove it;
|
|
|
|
- the data from the git-annex branch will be used, and the index
|
|
|
|
- will be automatically regenerated. -}
|
|
|
|
unlessM (liftAnnex $ Annex.Branch.withIndex $ inRepo $ Git.Repair.checkIndexFast) $ do
|
2021-04-05 17:40:31 +00:00
|
|
|
debug ["corrupt annex/index file found at startup; removing"]
|
2020-11-06 18:10:58 +00:00
|
|
|
liftAnnex $ liftIO . removeWhenExistsWith R.removeLink =<< fromRepo gitAnnexIndex
|
2013-11-13 18:27:17 +00:00
|
|
|
|
2013-12-21 00:58:36 +00:00
|
|
|
{- Fix up ssh remotes set up by past versions of the assistant. -}
|
|
|
|
liftIO $ fixUpSshRemotes
|
|
|
|
|
2014-04-28 01:15:26 +00:00
|
|
|
{- Clean up old temp files. -}
|
2019-01-17 19:40:44 +00:00
|
|
|
void $ liftAnnex $ tryNonAsync $ cleanupOtherTmp
|
2014-04-28 01:15:26 +00:00
|
|
|
|
2013-10-29 20:48:06 +00:00
|
|
|
{- If there's a startup delay, it's done here. -}
|
2013-10-26 16:42:58 +00:00
|
|
|
liftIO $ maybe noop (threadDelaySeconds . Seconds . fromIntegral . durationSeconds) startupdelay
|
|
|
|
|
|
|
|
{- Notify other threads that the startup sanity check is done. -}
|
|
|
|
status <- getDaemonStatus
|
|
|
|
liftIO $ sendNotification $ startupSanityCheckNotifier status
|
assistant: Detect stale git lock files at startup time, and remove them.
Extends the index.lock handling to other git lock files. I surveyed
all lock files used by git, and found more than I expected. All are
handled the same in git; it leaves them open while doing the operation,
possibly writing the new file content to the lock file, and then closes
them when done.
The gc.pid file is excluded because it won't affect the normal operation
of the assistant, and waiting for a gc to finish on startup wouldn't be
good.
All threads except the webapp thread wait on the new startup sanity checker
thread to complete, so they won't try to do things with git that fail
due to stale lock files. The webapp thread mostly avoids doing that kind of
thing itself. A few configurators might fail on lock files, but only if the
user is explicitly trying to run them. The webapp needs to start
immediately when the user has opened it, even if there are stale lock
files.
Arranging for the threads to wait on the startup sanity checker was a bit
of a bear. Have to get all the NotificationHandles set up before the
startup sanity checker runs, or they won't see its signal. Perhaps
the NotificationBroadcaster is not the best interface to have used for
this. Oh well, it works.
This commit was sponsored by Michael Jakl
2013-10-05 21:02:11 +00:00
|
|
|
|
2013-03-01 17:30:48 +00:00
|
|
|
{- This thread wakes up hourly for inxepensive frequent sanity checks. -}
|
|
|
|
sanityCheckerHourlyThread :: NamedThread
|
|
|
|
sanityCheckerHourlyThread = namedThread "SanityCheckerHourly" $ forever $ do
|
|
|
|
liftIO $ threadDelaySeconds $ Seconds oneHour
|
|
|
|
hourlyCheck
|
|
|
|
|
|
|
|
{- This thread wakes up daily to make sure the tree is in good shape. -}
|
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
|
|
|
sanityCheckerDailyThread :: UrlRenderer -> NamedThread
|
|
|
|
sanityCheckerDailyThread urlrenderer = namedThread "SanityCheckerDaily" $ forever $ do
|
2014-01-23 20:57:49 +00:00
|
|
|
waitForNextCheck
|
|
|
|
|
2012-10-29 06:21:04 +00:00
|
|
|
debug ["starting sanity check"]
|
2012-10-29 20:49:47 +00:00
|
|
|
void $ alertWhile sanityCheckAlert go
|
2012-10-29 06:21:04 +00:00
|
|
|
debug ["sanity check complete"]
|
|
|
|
where
|
|
|
|
go = do
|
2012-10-30 19:39:15 +00:00
|
|
|
modifyDaemonStatus_ $ \s -> s { sanityCheckRunning = True }
|
2012-10-29 06:21:04 +00:00
|
|
|
|
2013-10-03 02:59:07 +00:00
|
|
|
now <- liftIO getPOSIXTime -- before check started
|
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
|
|
|
r <- either showerr return
|
|
|
|
=<< (tryIO . batch) <~> dailyCheck urlrenderer
|
2012-07-29 21:53:18 +00:00
|
|
|
|
2012-10-30 19:39:15 +00:00
|
|
|
modifyDaemonStatus_ $ \s -> s
|
2012-10-29 06:21:04 +00:00
|
|
|
{ sanityCheckRunning = False
|
|
|
|
, lastSanityCheck = Just now
|
|
|
|
}
|
2012-07-29 21:53:18 +00:00
|
|
|
|
2012-10-29 06:21:04 +00:00
|
|
|
return r
|
2012-07-20 23:29:59 +00:00
|
|
|
|
2012-10-29 06:21:04 +00:00
|
|
|
showerr e = do
|
filter out control characters in warning messages
Converted warning and similar to use StringContainingQuotedPath. Most
warnings are static strings, some do refer to filepaths that need to be
quoted, and others don't need quoting.
Note that, since quote filters out control characters of even
UnquotedString, this makes all warnings safe, even when an attacker
sneaks in a control character in some other way.
When json is being output, no quoting is done, since json gets its own
quoting.
This does, as a side effect, make warning messages in json output not
be indented. The indentation is only needed to offset warning messages
underneath the display of the file they apply to, so that's ok.
Sponsored-by: Brett Eisenberg on Patreon
2023-04-10 18:47:32 +00:00
|
|
|
liftAnnex $ warning $ UnquotedString $ show e
|
2012-10-29 06:21:04 +00:00
|
|
|
return False
|
2012-07-30 06:07:02 +00:00
|
|
|
|
2012-06-13 21:54:23 +00:00
|
|
|
{- Only run one check per day, from the time of the last check. -}
|
2012-10-29 06:21:04 +00:00
|
|
|
waitForNextCheck :: Assistant ()
|
|
|
|
waitForNextCheck = do
|
2012-10-30 18:44:18 +00:00
|
|
|
v <- lastSanityCheck <$> getDaemonStatus
|
2012-10-29 06:21:04 +00:00
|
|
|
now <- liftIO getPOSIXTime
|
|
|
|
liftIO $ threadDelaySeconds $ Seconds $ calcdelay now v
|
|
|
|
where
|
|
|
|
calcdelay _ Nothing = oneDay
|
|
|
|
calcdelay now (Just lastcheck)
|
|
|
|
| lastcheck < now = max oneDay $
|
|
|
|
oneDay - truncate (now - lastcheck)
|
|
|
|
| otherwise = oneDay
|
2012-06-13 21:54:23 +00:00
|
|
|
|
2012-06-13 23:25:47 +00:00
|
|
|
{- It's important to stay out of the Annex monad as much as possible while
|
|
|
|
- running potentially expensive parts of this check, since remaining in it
|
|
|
|
- will block the watcher. -}
|
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
|
|
|
dailyCheck :: UrlRenderer -> Assistant Bool
|
|
|
|
dailyCheck urlrenderer = do
|
2014-09-15 18:45:37 +00:00
|
|
|
checkRepoExists
|
|
|
|
|
2012-10-29 06:21:04 +00:00
|
|
|
g <- liftAnnex gitRepo
|
2014-01-22 21:11:41 +00:00
|
|
|
batchmaker <- liftIO getBatchCommandMaker
|
2013-03-03 17:39:57 +00:00
|
|
|
|
2012-06-13 23:25:47 +00:00
|
|
|
-- Find old unstaged symlinks, and add them to git.
|
2020-05-28 19:55:17 +00:00
|
|
|
(unstaged, cleanup) <- liftIO $ Git.LsFiles.notInRepo [] False ["."] g
|
2013-10-03 02:59:07 +00:00
|
|
|
now <- liftIO getPOSIXTime
|
2012-06-13 23:25:47 +00:00
|
|
|
forM_ unstaged $ \file -> do
|
2023-03-01 19:55:58 +00:00
|
|
|
ms <- liftIO $ catchMaybeIO $ R.getSymbolicLinkStatus file
|
2012-06-13 23:25:47 +00:00
|
|
|
case ms of
|
|
|
|
Just s | toonew (statusChangeTime s) now -> noop
|
2023-03-01 19:55:58 +00:00
|
|
|
| isSymbolicLink s -> addsymlink (fromRawFilePath file) ms
|
2012-06-13 23:25:47 +00:00
|
|
|
_ -> noop
|
2012-10-29 06:21:04 +00:00
|
|
|
liftIO $ void cleanup
|
2013-03-03 17:39:57 +00:00
|
|
|
|
|
|
|
{- Allow git-gc to run once per day. More frequent gc is avoided
|
2013-03-03 18:07:13 +00:00
|
|
|
- by default to avoid slowing things down. Only run repacks when 100x
|
|
|
|
- the usual number of loose objects are present; we tend
|
|
|
|
- to have a lot of small objects and they should not be a
|
|
|
|
- significant size. -}
|
|
|
|
when (Git.Config.getMaybe "gc.auto" g == Just "0") $
|
2014-07-04 16:18:49 +00:00
|
|
|
liftIO $ void $ Git.Command.Batch.run batchmaker
|
2013-03-03 18:07:13 +00:00
|
|
|
[ Param "-c", Param "gc.auto=670000"
|
|
|
|
, Param "gc"
|
|
|
|
, Param "--auto"
|
|
|
|
] g
|
2013-03-03 17:39:57 +00:00
|
|
|
|
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
|
|
|
{- Check if the unused files found last time have been dealt with. -}
|
|
|
|
checkOldUnused urlrenderer
|
|
|
|
|
|
|
|
{- Run git-annex unused once per day. This is run as a separate
|
|
|
|
- process to stay out of the annex monad and so it can run as a
|
|
|
|
- batch job. -}
|
2015-02-28 21:23:13 +00:00
|
|
|
program <- liftIO programPath
|
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
|
|
|
let (program', params') = batchmaker (program, [Param "unused"])
|
|
|
|
void $ liftIO $ boolSystem program' params'
|
|
|
|
{- Invalidate unused keys cache, and queue transfers of all unused
|
2014-01-23 20:51:16 +00:00
|
|
|
- keys, or if no transfers are called for, drop them. -}
|
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
|
|
|
unused <- liftAnnex unusedKeys'
|
|
|
|
void $ liftAnnex $ setUnusedKeys unused
|
2014-01-23 20:51:16 +00:00
|
|
|
forM_ unused $ \k -> do
|
2017-03-10 17:12:24 +00:00
|
|
|
unlessM (queueTransfers "unused" Later k (AssociatedFile Nothing) Upload) $
|
|
|
|
handleDrops "unused" True k (AssociatedFile Nothing) []
|
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
|
|
|
|
2012-07-30 06:07:02 +00:00
|
|
|
return True
|
2012-10-29 06:21:04 +00:00
|
|
|
where
|
|
|
|
toonew timestamp now = now < (realToFrac (timestamp + slop) :: POSIXTime)
|
|
|
|
slop = fromIntegral tenMinutes
|
|
|
|
insanity msg = do
|
filter out control characters in warning messages
Converted warning and similar to use StringContainingQuotedPath. Most
warnings are static strings, some do refer to filepaths that need to be
quoted, and others don't need quoting.
Note that, since quote filters out control characters of even
UnquotedString, this makes all warnings safe, even when an attacker
sneaks in a control character in some other way.
When json is being output, no quoting is done, since json gets its own
quoting.
This does, as a side effect, make warning messages in json output not
be indented. The indentation is only needed to offset warning messages
underneath the display of the file they apply to, so that's ok.
Sponsored-by: Brett Eisenberg on Patreon
2023-04-10 18:47:32 +00:00
|
|
|
liftAnnex $ warning (UnquotedString msg)
|
2012-10-30 19:39:15 +00:00
|
|
|
void $ addAlert $ sanityCheckFixAlert msg
|
2012-10-29 06:21:04 +00:00
|
|
|
addsymlink file s = do
|
2019-08-26 19:52:19 +00:00
|
|
|
Watcher.runHandler Watcher.onAddSymlink file s
|
2012-10-29 06:21:04 +00:00
|
|
|
insanity $ "found unstaged symlink: " ++ file
|
2013-03-01 17:30:48 +00:00
|
|
|
|
|
|
|
hourlyCheck :: Assistant ()
|
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
|
|
|
hourlyCheck = do
|
2014-09-15 18:45:37 +00:00
|
|
|
checkRepoExists
|
2014-02-11 19:04:07 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
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
|
|
|
checkLogSize 0
|
2014-02-11 19:04:07 +00:00
|
|
|
#else
|
|
|
|
noop
|
|
|
|
#endif
|
2013-03-01 17:30:48 +00:00
|
|
|
|
2014-02-11 19:04:07 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
2014-03-05 22:26:53 +00:00
|
|
|
{- Rotate logs once when total log file size is > 2 mb.
|
|
|
|
-
|
|
|
|
- If total log size is larger than the amount of free disk space,
|
|
|
|
- continue rotating logs until size is < 2 mb, even if this
|
|
|
|
- results in immediately losing the just logged data.
|
|
|
|
-}
|
2013-03-01 17:30:48 +00:00
|
|
|
checkLogSize :: Int -> Assistant ()
|
|
|
|
checkLogSize n = do
|
2020-11-04 18:20:37 +00:00
|
|
|
f <- liftAnnex $ fromRawFilePath <$> fromRepo gitAnnexDaemonLogFile
|
2013-03-01 17:30:48 +00:00
|
|
|
logs <- liftIO $ listLogs f
|
2020-11-05 15:26:34 +00:00
|
|
|
totalsize <- liftIO $ sum <$> mapM (getFileSize . toRawFilePath) logs
|
2014-03-05 22:26:53 +00:00
|
|
|
when (totalsize > 2 * oneMegabyte) $ do
|
2021-04-05 17:40:31 +00:00
|
|
|
debug ["Rotated logs due to size:", show totalsize]
|
2014-06-17 23:10:51 +00:00
|
|
|
liftIO $ openLog f >>= handleToFd >>= redirLog
|
2014-03-05 22:26:53 +00:00
|
|
|
when (n < maxLogs + 1) $ do
|
|
|
|
df <- liftIO $ getDiskFree $ takeDirectory f
|
|
|
|
case df of
|
|
|
|
Just free
|
|
|
|
| free < fromIntegral totalsize ->
|
|
|
|
checkLogSize (n + 1)
|
|
|
|
_ -> noop
|
2013-03-01 17:30:48 +00:00
|
|
|
where
|
2015-01-20 20:58:48 +00:00
|
|
|
oneMegabyte :: Integer
|
2014-02-25 18:09:39 +00:00
|
|
|
oneMegabyte = 1000000
|
|
|
|
#endif
|
2013-03-01 17:30:48 +00:00
|
|
|
|
|
|
|
oneHour :: Int
|
|
|
|
oneHour = 60 * 60
|
|
|
|
|
|
|
|
oneDay :: Int
|
|
|
|
oneDay = 24 * oneHour
|
assistant: Detect stale git lock files at startup time, and remove them.
Extends the index.lock handling to other git lock files. I surveyed
all lock files used by git, and found more than I expected. All are
handled the same in git; it leaves them open while doing the operation,
possibly writing the new file content to the lock file, and then closes
them when done.
The gc.pid file is excluded because it won't affect the normal operation
of the assistant, and waiting for a gc to finish on startup wouldn't be
good.
All threads except the webapp thread wait on the new startup sanity checker
thread to complete, so they won't try to do things with git that fail
due to stale lock files. The webapp thread mostly avoids doing that kind of
thing itself. A few configurators might fail on lock files, but only if the
user is explicitly trying to run them. The webapp needs to start
immediately when the user has opened it, even if there are stale lock
files.
Arranging for the threads to wait on the startup sanity checker was a bit
of a bear. Have to get all the NotificationHandles set up before the
startup sanity checker runs, or they won't see its signal. Perhaps
the NotificationBroadcaster is not the best interface to have used for
this. Oh well, it works.
This commit was sponsored by Michael Jakl
2013-10-05 21:02:11 +00:00
|
|
|
|
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
|
|
|
{- If annex.expireunused is set, find any keys that have lingered unused
|
|
|
|
- for the specified duration, and remove them.
|
|
|
|
-
|
|
|
|
- Otherwise, check to see if unused keys are piling up, and let the user
|
2014-01-23 19:09:43 +00:00
|
|
|
- know. -}
|
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
|
|
|
checkOldUnused :: UrlRenderer -> Assistant ()
|
|
|
|
checkOldUnused urlrenderer = go =<< annexExpireUnused <$> liftAnnex Annex.getGitConfig
|
|
|
|
where
|
2014-01-23 03:10:51 +00:00
|
|
|
go (Just Nothing) = noop
|
2014-10-09 18:53:13 +00:00
|
|
|
go (Just (Just expireunused)) = expireUnused (Just expireunused)
|
2017-05-15 21:38:22 +00:00
|
|
|
go Nothing = maybe noop promptconfig =<< describeUnusedWhenBig
|
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
|
|
|
|
2017-05-15 21:38:22 +00:00
|
|
|
promptconfig msg =
|
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
|
|
|
#ifdef WITH_WEBAPP
|
|
|
|
do
|
2014-01-23 19:09:43 +00:00
|
|
|
button <- mkAlertButton True (T.pack "Configure") urlrenderer ConfigUnusedR
|
|
|
|
void $ addAlert $ unusedFilesAlert [button] $ T.unpack $ renderTense Present msg
|
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
|
|
|
#else
|
2014-02-08 18:18:36 +00:00
|
|
|
debug [show $ renderTense Past msg]
|
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
|
|
|
#endif
|
2014-04-28 01:15:26 +00:00
|
|
|
|
2014-09-15 18:45:37 +00:00
|
|
|
checkRepoExists :: Assistant ()
|
|
|
|
checkRepoExists = do
|
|
|
|
g <- liftAnnex gitRepo
|
2019-12-09 17:49:05 +00:00
|
|
|
liftIO $ unlessM (doesDirectoryExist $ fromRawFilePath $ Git.repoPath g) $
|
2014-09-15 18:45:37 +00:00
|
|
|
terminateSelf
|