pkg.re/essentialkaos/ek@v12.36.0+incompatible/fsutil/fs_darwin.go (about)

     1  // +build darwin
     2  
     3  package fsutil
     4  
     5  // ////////////////////////////////////////////////////////////////////////////////// //
     6  //                                                                                    //
     7  //                         Copyright (c) 2021 ESSENTIAL KAOS                          //
     8  //      Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0>     //
     9  //                                                                                    //
    10  // ////////////////////////////////////////////////////////////////////////////////// //
    11  
    12  import (
    13  	"syscall"
    14  	"time"
    15  
    16  	PATH "pkg.re/essentialkaos/ek.v12/path"
    17  )
    18  
    19  // ////////////////////////////////////////////////////////////////////////////////// //
    20  
    21  // GetTimes returns time of access, modification, and creation at once
    22  func GetTimes(path string) (time.Time, time.Time, time.Time, error) {
    23  	if path == "" {
    24  		return time.Time{}, time.Time{}, time.Time{}, ErrEmptyPath
    25  	}
    26  
    27  	path = PATH.Clean(path)
    28  
    29  	var stat = &syscall.Stat_t{}
    30  
    31  	err := syscall.Stat(path, stat)
    32  
    33  	if err != nil {
    34  		return time.Time{}, time.Time{}, time.Time{}, err
    35  	}
    36  
    37  	return time.Unix(int64(stat.Atimespec.Sec), int64(stat.Atimespec.Nsec)),
    38  		time.Unix(int64(stat.Mtimespec.Sec), int64(stat.Mtimespec.Nsec)),
    39  		time.Unix(int64(stat.Ctimespec.Sec), int64(stat.Ctimespec.Nsec)),
    40  		nil
    41  }
    42  
    43  // GetTimestamps returns time of access, modification, and creation at once as unix timestamp
    44  func GetTimestamps(path string) (int64, int64, int64, error) {
    45  	if path == "" {
    46  		return -1, -1, -1, ErrEmptyPath
    47  	}
    48  
    49  	path = PATH.Clean(path)
    50  
    51  	var stat = &syscall.Stat_t{}
    52  
    53  	err := syscall.Stat(path, stat)
    54  
    55  	if err != nil {
    56  		return -1, -1, -1, err
    57  	}
    58  
    59  	return int64(stat.Atimespec.Sec),
    60  		int64(stat.Mtimespec.Sec),
    61  		int64(stat.Ctimespec.Sec),
    62  		nil
    63  }
    64  
    65  // ////////////////////////////////////////////////////////////////////////////////// //
    66  
    67  func isEmptyDirent(n int) bool {
    68  	return n <= 0x40
    69  }