filecompare.go 763 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// +build !windows

package main

import (
  "os"
  "syscall"
)

func is_file_same(path string, info os.FileInfo, state *FileState) bool {
  fstat := info.Sys().(*syscall.Stat_t)
12
  return (fstat.Ino == state.Inode && fstat.Dev == state.Device)
13 14 15 16 17
}

func is_fileinfo_same(a os.FileInfo, b os.FileInfo) bool {
  af := a.Sys().(*syscall.Stat_t)
  bf := b.Sys().(*syscall.Stat_t)
18
  return (af.Dev == bf.Dev && af.Ino == bf.Ino)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
}

func is_file_renamed(file string, info os.FileInfo, fileinfo map[string]os.FileInfo) bool {
  stat := info.Sys().(*syscall.Stat_t)

  for kf, ki := range fileinfo {
    if kf == file {
      continue
    }
    ks := ki.Sys().(*syscall.Stat_t)
    if stat.Dev == ks.Dev && stat.Ino == ks.Ino {
      return true
    }
  }
  return false
}