From 454d71cafa7ec6ab2a47b686bb593327ff0239bd Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 2 Feb 2016 19:35:47 -0800 Subject: [PATCH] expiry: Remove auto-expiry. Move the logic outside and use scripting, cronjob to delete files. Fixes #1019 --- pkg/fs/auto-expiry.go | 41 ----------------------------------------- routers.go | 3 --- server-main.go | 26 +++----------------------- 3 files changed, 3 insertions(+), 67 deletions(-) delete mode 100644 pkg/fs/auto-expiry.go diff --git a/pkg/fs/auto-expiry.go b/pkg/fs/auto-expiry.go deleted file mode 100644 index 081c18ad9..000000000 --- a/pkg/fs/auto-expiry.go +++ /dev/null @@ -1,41 +0,0 @@ -package fs - -import ( - "os" - "time" -) - -// AutoExpiryThread - auto expiry thread -func (fs Filesystem) AutoExpiryThread(expiry time.Duration) { - expireFiles := func(fp string, fl os.FileInfo, err error) error { - if fp == fs.path { - return nil - } - if fl.Mode().IsRegular() || fl.Mode()&os.ModeSymlink == os.ModeSymlink { - if time.Now().Sub(fl.ModTime()) > expiry { - if err := os.Remove(fp); err != nil { - if os.IsNotExist(err) { - return nil - } - return err - } - } - return ErrDirNotEmpty - } - return nil - } - ticker := time.NewTicker(3 * time.Hour) - for { - select { - // TODO - add a way to stop the timer thread - case <-ticker.C: - err := WalkUnsorted(fs.path, expireFiles) - if err != nil { - if !os.IsNotExist(err) && err != ErrDirNotEmpty { - ticker.Stop() - return - } - } - } - } -} diff --git a/routers.go b/routers.go index 0d7fe5387..d9f4f05c5 100644 --- a/routers.go +++ b/routers.go @@ -146,9 +146,6 @@ func getNewCloudStorageAPI(conf cloudServerConfig) CloudStorageAPI { fatalIf(err.Trace(), "Initializing filesystem failed.", nil) fs.SetMinFreeDisk(conf.MinFreeDisk) - if conf.Expiry > 0 { - go fs.AutoExpiryThread(conf.Expiry) - } return CloudStorageAPI{ Filesystem: fs, AccessLog: conf.AccessLog, diff --git a/server-main.go b/server-main.go index 628df3e27..207856e21 100644 --- a/server-main.go +++ b/server-main.go @@ -26,7 +26,6 @@ import ( "runtime" "strconv" "strings" - "time" "github.com/fatih/color" "github.com/minio/cli" @@ -44,7 +43,6 @@ var serverCmd = cli.Command{ USAGE: minio {{.Name}} [OPTION VALUE] PATH - OPTION = expiry VALUE = NN[h|m|s] [DEFAULT=Unlimited] OPTION = min-free-disk VALUE = NN% [DEFAULT: 10%] EXAMPLES: @@ -60,9 +58,6 @@ EXAMPLES: 4. Start minio server with minimum free disk threshold to 5% $ minio {{.Name}} min-free-disk 5% /home/shared/Pictures - 5. Start minio server with minimum free disk threshold to 15% with auto expiration set to 1h - $ minio {{.Name}} min-free-disk 15% expiry 1h /home/shared/Documents - `, } @@ -77,9 +72,8 @@ type cloudServerConfig struct { SecretAccessKey string // Secret access key. /// FS options - Path string // Path to export for cloud storage - MinFreeDisk int64 // Minimum free disk space for filesystem - Expiry time.Duration // Set auto expiry for filesystem + Path string // Path to export for cloud storage + MinFreeDisk int64 // Minimum free disk space for filesystem /// TLS service TLS bool // TLS on when certs are specified @@ -297,11 +291,8 @@ func serverMain(c *cli.Context) { // Default minFreeDisk = 10 - var expiration time.Duration - expirationSet := false - args := c.Args() - for len(args) >= 2 { + for len(args) >= 1 { switch args.First() { case "min-free-disk": if minFreeDiskSet { @@ -313,16 +304,6 @@ func serverMain(c *cli.Context) { fatalIf(err.Trace(args.First()), "Invalid minium free disk size "+args.First()+" passed.", nil) args = args.Tail() minFreeDiskSet = true - case "expiry": - if expirationSet { - fatalIf(probe.NewError(errInvalidArgument), "Expiration should be set only once.", nil) - } - args = args.Tail() - var err error - expiration, err = time.ParseDuration(args.First()) - fatalIf(probe.NewError(err), "Invalid expiration time "+args.First()+" passed.", nil) - args = args.Tail() - expirationSet = true default: cli.ShowCommandHelpAndExit(c, "server", 1) // last argument is exit code } @@ -341,7 +322,6 @@ func serverMain(c *cli.Context) { SecretAccessKey: conf.Credentials.SecretAccessKey, Path: path, MinFreeDisk: minFreeDisk, - Expiry: expiration, TLS: tls, CertFile: certFile, KeyFile: keyFile,