github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/backend/local/metadata_windows.go (about)

     1  //go:build windows
     2  
     3  package local
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  	"syscall"
     9  	"time"
    10  
    11  	"github.com/rclone/rclone/fs"
    12  )
    13  
    14  // Read the time specified from the os.FileInfo
    15  func readTime(t timeType, fi os.FileInfo) time.Time {
    16  	stat, ok := fi.Sys().(*syscall.Win32FileAttributeData)
    17  	if !ok {
    18  		fs.Debugf(nil, "didn't return Win32FileAttributeData as expected")
    19  		return fi.ModTime()
    20  	}
    21  	switch t {
    22  	case aTime:
    23  		return time.Unix(0, stat.LastAccessTime.Nanoseconds())
    24  	case bTime:
    25  		return time.Unix(0, stat.CreationTime.Nanoseconds())
    26  	}
    27  	return fi.ModTime()
    28  }
    29  
    30  // Read the metadata from the file into metadata where possible
    31  func (o *Object) readMetadataFromFile(m *fs.Metadata) (err error) {
    32  	info, err := o.fs.lstat(o.path)
    33  	if err != nil {
    34  		return err
    35  	}
    36  	stat, ok := info.Sys().(*syscall.Win32FileAttributeData)
    37  	if !ok {
    38  		fs.Debugf(o, "didn't return Win32FileAttributeData as expected")
    39  		return nil
    40  	}
    41  	// FIXME do something with stat.FileAttributes ?
    42  	m.Set("mode", fmt.Sprintf("%0o", info.Mode()))
    43  	setTime := func(key string, t syscall.Filetime) {
    44  		m.Set(key, time.Unix(0, t.Nanoseconds()).Format(metadataTimeFormat))
    45  	}
    46  	setTime("atime", stat.LastAccessTime)
    47  	setTime("mtime", stat.LastWriteTime)
    48  	setTime("btime", stat.CreationTime)
    49  	return nil
    50  }