Skip to content

Commit

Permalink
fix getting inode for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Sep 2, 2020
1 parent 78492f6 commit 4a64820
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 23 deletions.
18 changes: 8 additions & 10 deletions internal/inode/inode_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import (
"syscall"
)

func Get(fi os.FileInfo) (uint64, error) {
stat := fi.Sys().(*syscall.Stat_t)
return stat.Ino, nil
}

func GetPath(path string) (uint64, error) {
fi, err := os.Stat(path)
if err != nil {
return 0, err
func Get(path string, fi os.FileInfo) (uint64, error) {
if fi == nil {
var err error
fi, err = os.Stat(path)
if err != nil {
return 0, err
}
}
return Get(fi)
return fi.Sys().(*syscall.Stat_t).Ino, nil
}
6 changes: 1 addition & 5 deletions internal/inode/inode_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import (
"syscall"
)

func Get(fi os.FileInfo) (uint64, error) {
return GetPath(fi.Name())
}

func GetPath(path string) (uint64, error) {
func Get(path string, _ os.FileInfo) (uint64, error) {
f, err := os.Open(path)
if err != nil {
return 0, err
Expand Down
2 changes: 1 addition & 1 deletion job_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (d *downloadJob) Run(ctx context.Context) error {
return err
}

in, err := inode.GetPath(newPath)
in, err := inode.Get(newPath, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion job_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (j *writeFileStateJob) String() string {
}

func (j *writeFileStateJob) Run(ctx context.Context) error {
in, err := inode.Get(j.localFile.Info())
in, err := inode.Get(j.localFile.FullPath(), j.localFile.Info())
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions job_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (d *uploadJob) tryResume(ctx context.Context) bool {
if d.state.Size != d.localFile.Info().Size() {
return false
}
in, _ := inode.Get(d.localFile.Info())
in, _ := inode.Get(d.localFile.FullPath(), d.localFile.Info())
if d.state.LocalInode != in {
return false
}
Expand All @@ -48,7 +48,7 @@ func (d *uploadJob) tryResume(ctx context.Context) bool {
func (d *uploadJob) Run(ctx context.Context) error {
ok := d.tryResume(ctx)
if !ok {
in, err := inode.Get(d.localFile.Info())
in, err := inode.Get(d.localFile.FullPath(), d.localFile.Info())
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions recon.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func syncWithState(sf *syncFile, filesByRemoteID map[int64]*syncFile, filesByIno
// There is no existing state in move target
if target.remote.PutioFile().CRC32 == sf.state.CRC32 {
// Remote file is not changed
in, _ := inode.Get(sf.local.Info())
in, _ := inode.Get(sf.local.FullPath(), sf.local.Info())
if in == sf.state.LocalInode {
// Local file is not changed too
// Then, file must be moved. We can move the local file to same path.
Expand All @@ -161,7 +161,7 @@ func syncWithState(sf *syncFile, filesByRemoteID map[int64]*syncFile, filesByIno
if target.state == nil {
if sf.remote.PutioFile().CRC32 == sf.state.CRC32 {
// Remote file is not changed
in, _ := inode.Get(target.local.Info())
in, _ := inode.Get(target.local.FullPath(), target.local.Info())
if in == sf.state.LocalInode {
// Local file is not changed too
// Then, file must be moved. We can move the remote file to same path.
Expand Down Expand Up @@ -208,7 +208,7 @@ func syncWithState(sf *syncFile, filesByRemoteID map[int64]*syncFile, filesByIno
}
case statusUploading:
if sf.local != nil && sf.remote == nil {
in, _ := inode.Get(sf.local.Info())
in, _ := inode.Get(sf.local.FullPath(), sf.local.Info())
if in == sf.state.LocalInode {
// Local file is still the same, resume upload
return []iJob{&uploadJob{
Expand Down Expand Up @@ -271,7 +271,7 @@ func mapLocalFilesByInode(syncFiles map[string]*syncFile) map[uint64]*syncFile {
m := make(map[uint64]*syncFile, len(syncFiles))
for _, sf := range syncFiles {
if sf.local != nil {
in, err := inode.Get(sf.local.Info())
in, err := inode.Get(sf.local.FullPath(), sf.local.Info())
if err != nil {
log.Error(err)
continue
Expand Down

0 comments on commit 4a64820

Please sign in to comment.