You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
917 B
Go
55 lines
917 B
Go
package history
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"syscall"
|
|
)
|
|
|
|
const historyFile = "rqlite_history"
|
|
|
|
func setHidden(path string) error {
|
|
filenameW, err := syscall.UTF16PtrFromString(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = syscall.SetFileAttributes(filenameW, syscall.FILE_ATTRIBUTE_HIDDEN)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Reader returns a reader of the history file.
|
|
func Reader() io.ReadCloser {
|
|
hdir, err := os.UserHomeDir()
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
f, err := os.Open(filepath.Join(hdir, historyFile))
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return f
|
|
}
|
|
|
|
// Writer returns a writer for the history file.
|
|
func Writer() io.WriteCloser {
|
|
hdir, err := os.UserHomeDir()
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
path := filepath.Join(hdir, historyFile)
|
|
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0755)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
setHidden(path) // best effort
|
|
return f
|
|
}
|