Skip to content

Commit

Permalink
Merge pull request #15 from joyme123/fix-windows
Browse files Browse the repository at this point in the history
fix: fix build on windows
  • Loading branch information
joyme123 authored Aug 10, 2023
2 parents 7344a42 + dbd5257 commit 6832cef
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 16 deletions.
4 changes: 2 additions & 2 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
)

func Init() {
file := "/tmp/thriftls.log"

file := os.TempDir() + "/thriftls.log"
logFile, err := os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
if err != nil {
panic(err)
Expand All @@ -17,5 +18,4 @@ func Init() {
}

type Logger struct {

}
14 changes: 0 additions & 14 deletions lsp/cache/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (
"context"
"crypto/sha256"
"fmt"
"os"
"sync"
"syscall"
"time"

"go.lsp.dev/protocol"
Expand All @@ -28,18 +26,6 @@ type FileID struct {
// Like os.Stat, it reads through symbolic links.
func GetFileID(filename string) (FileID, time.Time, error) { return getFileID(filename) }

func getFileID(filename string) (FileID, time.Time, error) {
fi, err := os.Stat(filename)
if err != nil {
return FileID{}, time.Time{}, err
}
stat := fi.Sys().(*syscall.Stat_t)
return FileID{
device: uint64(stat.Dev), // (int32 on darwin, uint64 on linux)
inode: stat.Ino,
}, fi.ModTime(), nil
}

type Hash [sha256.Size]byte

// HashOf returns the hash of some data.
Expand Down
22 changes: 22 additions & 0 deletions lsp/cache/file_posix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build !windows && !plan9
// +build !windows,!plan9

package cache

import (
"os"
"syscall"
"time"
)

func getFileID(filename string) (FileID, time.Time, error) {
fi, err := os.Stat(filename)
if err != nil {
return FileID{}, time.Time{}, err
}
stat := fi.Sys().(*syscall.Stat_t)
return FileID{
device: uint64(stat.Dev), // (int32 on darwin, uint64 on linux)
inode: stat.Ino,
}, fi.ModTime(), nil
}
33 changes: 33 additions & 0 deletions lsp/cache/file_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//go:build windows
// +build windows

package cache

import (
"syscall"
"time"
)

// Note: it may be convenient to have this helper return fs.FileInfo, but
// implementing this is actually quite involved on Windows. Since we only
// currently use mtime, keep it simple.
func getFileID(filename string) (FileID, time.Time, error) {
filename16, err := syscall.UTF16PtrFromString(filename)
if err != nil {
return FileID{}, time.Time{}, err
}
h, err := syscall.CreateFile(filename16, 0, 0, nil, syscall.OPEN_EXISTING, uint32(syscall.FILE_FLAG_BACKUP_SEMANTICS), 0)
if err != nil {
return FileID{}, time.Time{}, err
}
defer syscall.CloseHandle(h)
var i syscall.ByHandleFileInformation
if err := syscall.GetFileInformationByHandle(h, &i); err != nil {
return FileID{}, time.Time{}, err
}
mtime := time.Unix(0, i.LastWriteTime.Nanoseconds())
return FileID{
device: uint64(i.VolumeSerialNumber),
inode: uint64(i.FileIndexHigh)<<32 | uint64(i.FileIndexLow),
}, mtime, nil
}

0 comments on commit 6832cef

Please sign in to comment.