Exemple #1
0
// removeOldKeys removes keys older than specified age
func removeOldKeys() error {
	datas, err := backends.List()
	if err != nil {
		return err
	}

	now := time.Now()

	lumber.Debug("Garbage Collector - Finding files...")
	for _, data := range datas {

		// clean-after defaults to Now() to ensure no files are deleted in case
		// cobra decides to change how 'Command.Flag().Changed' works. It does this
		// because no files, written by hoarder, will have a modified time before the
		// Unix epoch began
		if data.ModTime.Unix() < (now.Unix() - int64(viper.GetInt("clean-after"))) {
			lumber.Debug("Cleaning key: ", data.Name)
			if err := backends.Remove(data.Name); err != nil {
				return fmt.Errorf("Cleaning of '%s' failed - %v", data.Name, err.Error())
			}
		}
	}

	return nil
}
Exemple #2
0
// delete removes key and corresponding data
func delete(rw http.ResponseWriter, req *http.Request) {

	key := req.URL.Query().Get(":blob")

	//
	if err := backends.Remove(key); err != nil {
		rw.Write([]byte(fmt.Sprintf("%s\n", err.Error())))
		return
	}

	//
	rw.Write([]byte(fmt.Sprintf("'%s' destroyed!\n", key)))
}
Exemple #3
0
// ensure remove idempotency
func TestRemove2(t *testing.T) {
	err := backends.Remove("testfile")
	if err != nil {
		t.Error("Failed to REMOVE file - ", err)
	}
}