2017-05-02 06:25:56 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/andreimarcu/linx-server/backends/localfs"
|
|
|
|
"github.com/andreimarcu/linx-server/expiry"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var filesDir string
|
|
|
|
var metaDir string
|
|
|
|
var noLogs bool
|
|
|
|
|
|
|
|
flag.StringVar(&filesDir, "filespath", "files/",
|
|
|
|
"path to files directory")
|
|
|
|
flag.StringVar(&metaDir, "metapath", "meta/",
|
|
|
|
"path to metadata directory")
|
|
|
|
flag.BoolVar(&noLogs, "nologs", false,
|
|
|
|
"don't log deleted files")
|
2017-05-04 06:12:41 +02:00
|
|
|
flag.Parse()
|
2017-05-02 06:25:56 +02:00
|
|
|
|
2019-01-25 08:33:11 +01:00
|
|
|
fileBackend := localfs.NewLocalfsBackend(metaDir, filesDir)
|
2017-05-02 06:25:56 +02:00
|
|
|
|
2019-01-25 08:33:11 +01:00
|
|
|
files, err := fileBackend.List()
|
2017-05-02 06:25:56 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, filename := range files {
|
2019-01-25 08:33:11 +01:00
|
|
|
metadata, err := fileBackend.Head(filename)
|
2017-05-02 06:25:56 +02:00
|
|
|
if err != nil {
|
2018-02-25 23:46:20 +01:00
|
|
|
if !noLogs {
|
|
|
|
log.Printf("Failed to find metadata for %s", filename)
|
|
|
|
}
|
2017-05-02 06:25:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if expiry.IsTsExpired(metadata.Expiry) {
|
2018-02-25 23:46:20 +01:00
|
|
|
if !noLogs {
|
|
|
|
log.Printf("Delete %s", filename)
|
|
|
|
}
|
2017-05-02 06:25:56 +02:00
|
|
|
fileBackend.Delete(filename)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|