Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add accesstime support #798

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func Run() (err error) {
&cli.BoolFlag{Name: "no-local", Usage: "disable local relay when sending"},
&cli.BoolFlag{Name: "no-multi", Usage: "disable multiplexing"},
&cli.BoolFlag{Name: "git", Usage: "enable .gitignore respect / don't send ignored files"},
&cli.BoolFlag{Name: "preserve", Usage: "preserves modification times, access times, and file mode bits from the source file."},
&cli.IntFlag{Name: "port", Value: 9009, Usage: "base port for the relay"},
&cli.IntFlag{Name: "transfers", Value: 4, Usage: "number of ports to use for transfers"},
},
Expand Down Expand Up @@ -301,6 +302,7 @@ func send(c *cli.Context) (err error) {
ThrottleUpload: c.String("throttleUpload"),
ZipFolder: c.Bool("zip"),
GitIgnore: c.Bool("git"),
Preserve: c.Bool("preserve"),
}
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
crocOptions.RelayAddress6 = ""
Expand Down Expand Up @@ -349,6 +351,9 @@ func send(c *cli.Context) (err error) {
if !c.IsSet("git") {
crocOptions.GitIgnore = rememberedOptions.GitIgnore
}
if !c.IsSet("preserve") {
crocOptions.Preserve = rememberedOptions.Preserve
}
}

var fnames []string
Expand Down
21 changes: 20 additions & 1 deletion src/croc/croc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
"syscall"
"time"

"golang.org/x/term"
Expand Down Expand Up @@ -83,6 +85,7 @@ type Options struct {
ZipFolder bool
TestFlag bool
GitIgnore bool
Preserve bool
}

type SimpleMessage struct {
Expand Down Expand Up @@ -156,6 +159,7 @@ type FileInfo struct {
Hash []byte `json:"h,omitempty"`
Size int64 `json:"s,omitempty"`
ModTime time.Time `json:"m,omitempty"`
AccessTime time.Time `json:"a,omitempty"`
IsCompressed bool `json:"c,omitempty"`
IsEncrypted bool `json:"e,omitempty"`
Symlink string `json:"sy,omitempty"`
Expand Down Expand Up @@ -367,14 +371,18 @@ func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool) (filesInfo []
}
}
}
var accesstime time.Time
for _, fpath := range paths {
stat, errStat := os.Lstat(fpath)

if errStat != nil {
err = errStat
return
}

if err != nil {
err = errStat
return
}
absPath, errAbs := filepath.Abs(fpath)

if errAbs != nil {
Expand All @@ -400,12 +408,21 @@ func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool) (filesInfo []
return
}

if runtime.GOOS != "windows" {
atime := stat.Sys().(*syscall.Stat_t).Atim
accesstime = time.Unix(0, atime.Nano())
} else {
// fileTime := stat.Sys().(*syscall.Win32FileAttributeData).LastAccessTime
// accesstime = time.Unix(0, fileTime.Nanoseconds())
}

fInfo := FileInfo{
Name: stat.Name(),
FolderRemote: "./",
FolderSource: filepath.Dir(absPath),
Size: stat.Size(),
ModTime: stat.ModTime(),
AccessTime: accesstime,
Mode: stat.Mode(),
TempFile: true,
IsIgnored: ignoredPaths[absPath],
Expand Down Expand Up @@ -439,6 +456,7 @@ func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool) (filesInfo []
Size: info.Size(),
ModTime: info.ModTime(),
Mode: info.Mode(),
AccessTime: accesstime,
TempFile: false,
IsIgnored: ignoredPaths[pathName],
}
Expand Down Expand Up @@ -474,6 +492,7 @@ func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool) (filesInfo []
FolderSource: filepath.Dir(absPath),
Size: stat.Size(),
ModTime: stat.ModTime(),
AccessTime: accesstime,
Mode: stat.Mode(),
TempFile: false,
IsIgnored: ignoredPaths[absPath],
Expand Down
Loading