forked from axiom-data-science/usher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapper_mtime.go
More file actions
35 lines (30 loc) · 892 Bytes
/
mapper_mtime.go
File metadata and controls
35 lines (30 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package usher
import (
"errors"
"log"
"os"
"strings"
)
type MtimeFileMapper struct {
DatePathFormat string
}
func NewMtimeFileMapper(datePathFormat string) *MtimeFileMapper {
if len(datePathFormat) > 0 && !strings.HasSuffix(datePathFormat, "/") {
datePathFormat += "/"
}
return &MtimeFileMapper{datePathFormat}
}
func (fm *MtimeFileMapper) GetFileDestPath(relSrcFile string, absSrcFile string,
baseSrcFile string, mappedRootSrcPath string, mappedRootDestPath string) (string, error) {
//stat source file for last modified time
srcStat, err := os.Stat(absSrcFile)
if err != nil {
log.Println(err)
return "", errors.New("couldn't stat source file " + relSrcFile + ", skipping")
}
//set default date pattern if none was set
if len(fm.DatePathFormat) == 0 {
fm.DatePathFormat = "2006/01/02/"
}
return srcStat.ModTime().Format(fm.DatePathFormat) + baseSrcFile, nil
}