github.com/cockroachdb/tools@v0.0.0-20230222021103-a6d27438930d/internal/robustio/robustio_posix.go (about)

     1  // Copyright 2022 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build !windows && !plan9
     6  // +build !windows,!plan9
     7  
     8  // TODO(adonovan): use 'unix' tag when go1.19 can be assumed.
     9  
    10  package robustio
    11  
    12  import (
    13  	"os"
    14  	"syscall"
    15  	"time"
    16  )
    17  
    18  func getFileID(filename string) (FileID, time.Time, error) {
    19  	fi, err := os.Stat(filename)
    20  	if err != nil {
    21  		return FileID{}, time.Time{}, err
    22  	}
    23  	stat := fi.Sys().(*syscall.Stat_t)
    24  	return FileID{
    25  		device: uint64(stat.Dev), // (int32 on darwin, uint64 on linux)
    26  		inode:  stat.Ino,
    27  	}, fi.ModTime(), nil
    28  }