pkg.re/essentialkaos/ek.10@v12.41.0+incompatible/fsutil/fs_freebsd.go (about)

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