|
|
@ -4,11 +4,13 @@ import (
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"path"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
// "io"
|
|
|
|
"io/fs"
|
|
|
|
"caj-larsson/bog/dataswamp/swampfile"
|
|
|
|
"caj-larsson/bog/dataswamp/swampfile"
|
|
|
|
"github.com/spf13/afero"
|
|
|
|
"github.com/spf13/afero"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type SwampFile struct {
|
|
|
|
type SwampFile struct {
|
|
|
|
filename string
|
|
|
|
filename string
|
|
|
|
file afero.File
|
|
|
|
file afero.File
|
|
|
@ -54,7 +56,7 @@ func NewRepository() swampfile.Repository {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (r Repository) Create(filename string, namespace_stub string) (swampfile.SwampInFile, error) {
|
|
|
|
func (r Repository) Create(filename string, namespace_stub string) (swampfile.SwampInFile, error) {
|
|
|
|
abs_path := path.Join(filename, namespace_stub)
|
|
|
|
abs_path := path.Join(namespace_stub, filename)
|
|
|
|
dir := path.Dir(abs_path)
|
|
|
|
dir := path.Dir(abs_path)
|
|
|
|
r.fs.MkdirAll(dir, 0750)
|
|
|
|
r.fs.MkdirAll(dir, 0750)
|
|
|
|
file, err := r.fs.OpenFile(abs_path, os.O_RDWR|os.O_CREATE, 0644)
|
|
|
|
file, err := r.fs.OpenFile(abs_path, os.O_RDWR|os.O_CREATE, 0644)
|
|
|
@ -69,7 +71,7 @@ func (r Repository) Create(filename string, namespace_stub string) (swampfile.Sw
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (r Repository) Open(filename string, namespace_stub string) (swampfile.SwampOutFile, error) {
|
|
|
|
func (r Repository) Open(filename string, namespace_stub string) (swampfile.SwampOutFile, error) {
|
|
|
|
abs_path := path.Join(filename, namespace_stub)
|
|
|
|
abs_path := path.Join(namespace_stub, filename)
|
|
|
|
|
|
|
|
|
|
|
|
dir := path.Dir(abs_path)
|
|
|
|
dir := path.Dir(abs_path)
|
|
|
|
r.fs.MkdirAll(dir, 0750)
|
|
|
|
r.fs.MkdirAll(dir, 0750)
|
|
|
@ -84,6 +86,27 @@ func (r Repository) Open(filename string, namespace_stub string) (swampfile.Swam
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (r Repository) Delete(filename string, namespace_stub string) {
|
|
|
|
func (r Repository) Delete(filename string, namespace_stub string) {
|
|
|
|
abs_path := path.Join(filename, namespace_stub)
|
|
|
|
abs_path := path.Join(namespace_stub, filename)
|
|
|
|
r.fs.Remove(abs_path)
|
|
|
|
r.fs.Remove(abs_path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (r Repository) DeleteOlderThan(namespace_stub string, ts time.Time) error {
|
|
|
|
|
|
|
|
err := afero.Walk(r.fs, namespace_stub, func(path string, info fs.FileInfo, err error) error {
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if info.Mode().IsRegular() && ts.Before(info.ModTime()) {
|
|
|
|
|
|
|
|
r.fs.Remove(path)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !info.Mode().IsDir() {
|
|
|
|
|
|
|
|
return swampfile.ErrCorrupted
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|