Allow to update organized file's mtime corresponding to the original file's creation date

This commit is contained in:
2019-09-10 14:14:42 +03:00
parent ddce47312e
commit 9f86a08c82
3 changed files with 19 additions and 8 deletions

View File

@@ -7,6 +7,7 @@ import (
"os/exec"
"path"
"strings"
"time"
"github.com/pkg/errors"
@@ -14,18 +15,20 @@ import (
)
type Manager struct {
TargetPath string
Mode ManageMode
TargetPath string
Mode ManageMode
updateMtime bool
processor func(fp, targetDir string) (string, error)
extractorsCache map[string]metadata.Extractor
}
func NewManager(target string, mode ManageMode) (*Manager, error) {
func NewManager(target string, mode ManageMode, updateMtime bool) (*Manager, error) {
manager := Manager{
TargetPath: target,
Mode: mode,
processor: nil,
TargetPath: target,
Mode: mode,
processor: nil,
updateMtime: updateMtime,
}
if err := manager.initProcessor(); err != nil {
return nil, err
@@ -123,6 +126,13 @@ func (m *Manager) Manage(fp string) error {
return errors.WithMessagef(err, "failed to process %s to %s", fp, targetDir)
}
if m.updateMtime {
err = os.Chtimes(target, time.Now(), md.Time)
if err != nil {
return errors.WithMessage(err, "failed to update mtime/atime")
}
}
if m.Mode == Hardlink {
log.Println(fp, "linked to", target)
} else if m.Mode == Copy {