mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-25 17:52:02 +02:00
Fix building of kitten on other platforms
This commit is contained in:
@@ -12,10 +12,9 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"kitty/tools/config"
|
"kitty/tools/config"
|
||||||
|
"kitty/tools/stat"
|
||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
"kitty/tools/utils/paths"
|
"kitty/tools/utils/paths"
|
||||||
"kitty/tools/utils/shlex"
|
"kitty/tools/utils/shlex"
|
||||||
@@ -242,31 +241,30 @@ func excluded(pattern, path string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func get_file_data(callback func(h *tar.Header, data []byte) error, seen map[file_unique_id]string, local_path, arcname string, exclude_patterns []string) error {
|
func get_file_data(callback func(h *tar.Header, data []byte) error, seen map[file_unique_id]string, local_path, arcname string, exclude_patterns []string) error {
|
||||||
s, err := os.Lstat(local_path)
|
s_, err := os.Lstat(local_path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
u, unix_stat_conv_ok := s.Sys().(*syscall.Stat_t)
|
s := stat.Get(s_)
|
||||||
if u == nil {
|
|
||||||
unix_stat_conv_ok = false
|
|
||||||
}
|
|
||||||
cb := func(h *tar.Header, data []byte, arcname string) error {
|
cb := func(h *tar.Header, data []byte, arcname string) error {
|
||||||
h.Name = arcname
|
h.Name = arcname
|
||||||
if h.Typeflag == tar.TypeDir {
|
if h.Typeflag == tar.TypeDir {
|
||||||
h.Name = strings.TrimRight(h.Name, "/") + "/"
|
h.Name = strings.TrimRight(h.Name, "/") + "/"
|
||||||
}
|
}
|
||||||
h.Size = int64(len(data))
|
h.Size = int64(len(data))
|
||||||
h.Mode = int64(s.Mode().Perm())
|
h.Mode = int64(s.Mode.Perm())
|
||||||
h.ModTime = s.ModTime()
|
h.ModTime = s.Mtime
|
||||||
h.Format = tar.FormatPAX
|
h.Format = tar.FormatPAX
|
||||||
if unix_stat_conv_ok {
|
if s.Has_atime {
|
||||||
h.AccessTime = time.Unix(0, u.Atim.Nano())
|
h.AccessTime = s.Atime
|
||||||
h.ChangeTime = time.Unix(0, u.Ctim.Nano())
|
}
|
||||||
|
if s.Has_ctime {
|
||||||
|
h.ChangeTime = s.Ctime
|
||||||
}
|
}
|
||||||
return callback(h, data)
|
return callback(h, data)
|
||||||
}
|
}
|
||||||
// we only copy regular files, directories and symlinks
|
// we only copy regular files, directories and symlinks
|
||||||
switch s.Mode().Type() {
|
switch s.Mode.Type() {
|
||||||
case fs.ModeSymlink:
|
case fs.ModeSymlink:
|
||||||
target, err := os.Readlink(local_path)
|
target, err := os.Readlink(local_path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -323,8 +321,8 @@ func get_file_data(callback func(h *tar.Header, data []byte) error, seen map[fil
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 0: // Regular file
|
case 0: // Regular file
|
||||||
if unix_stat_conv_ok {
|
if s.Has_ino && s.Has_dev {
|
||||||
fid := file_unique_id{dev: uint64(u.Dev), inode: uint64(u.Ino)}
|
fid := file_unique_id{dev: s.Dev, inode: s.Ino}
|
||||||
if prev, ok := seen[fid]; ok { // Hard link
|
if prev, ok := seen[fid]; ok { // Hard link
|
||||||
return cb(&tar.Header{Typeflag: tar.TypeLink, Linkname: prev}, nil, arcname)
|
return cb(&tar.Header{Typeflag: tar.TypeLink, Linkname: prev}, nil, arcname)
|
||||||
}
|
}
|
||||||
|
|||||||
51
tools/stat/api.go
Normal file
51
tools/stat/api.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package stat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = fmt.Print
|
||||||
|
|
||||||
|
type StatResult struct {
|
||||||
|
Name string
|
||||||
|
Size int64
|
||||||
|
Mode fs.FileMode
|
||||||
|
Ctime, Mtime, Atime time.Time
|
||||||
|
Has_ctime, Has_atime bool
|
||||||
|
Dev, Ino uint64
|
||||||
|
Has_dev, Has_ino bool
|
||||||
|
Number_links uint64
|
||||||
|
Has_number_links bool
|
||||||
|
Uid, Gid uint64
|
||||||
|
Has_uid, Has_gid bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StatResult) setup_common(f fs.FileInfo) (u *syscall.Stat_t) {
|
||||||
|
s.Name = f.Name()
|
||||||
|
s.Size = f.Size()
|
||||||
|
s.Mode = f.Mode()
|
||||||
|
s.Mtime = f.ModTime()
|
||||||
|
ok := false
|
||||||
|
u, ok = f.Sys().(*syscall.Stat_t)
|
||||||
|
if !ok {
|
||||||
|
u = nil
|
||||||
|
}
|
||||||
|
if u != nil {
|
||||||
|
s.Has_atime = true
|
||||||
|
s.Has_ctime = true
|
||||||
|
s.Dev = uint64(u.Dev)
|
||||||
|
s.Ino = uint64(u.Ino)
|
||||||
|
s.Has_dev = true
|
||||||
|
s.Has_ino = true
|
||||||
|
s.Number_links = uint64(u.Nlink)
|
||||||
|
s.Has_number_links = true
|
||||||
|
s.Uid = uint64(u.Uid)
|
||||||
|
s.Gid = uint64(u.Gid)
|
||||||
|
s.Has_uid = true
|
||||||
|
s.Has_gid = true
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
20
tools/stat/get1.go
Normal file
20
tools/stat/get1.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
//go:build aix || linux || dragonfly || openbsd || solaris
|
||||||
|
|
||||||
|
package stat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = fmt.Print
|
||||||
|
|
||||||
|
func Get(f fs.FileInfo) (ans StatResult) {
|
||||||
|
u := ans.setup_common(f)
|
||||||
|
if u != nil {
|
||||||
|
ans.Ctime = time.Unix(u.Ctim.Unix())
|
||||||
|
ans.Atime = time.Unix(u.Atim.Unix())
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
20
tools/stat/get2.go
Normal file
20
tools/stat/get2.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
//go:build darwin || freebsd || netbsd
|
||||||
|
|
||||||
|
package stat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = fmt.Print
|
||||||
|
|
||||||
|
func Get(f fs.FileInfo) (ans StatResult) {
|
||||||
|
u := ans.setup_common(f)
|
||||||
|
if u != nil {
|
||||||
|
ans.Ctime = time.Unix(u.Ctimespec.Unix())
|
||||||
|
ans.Atime = time.Unix(u.Atimespec.Unix())
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user