Skip to content

Commit

Permalink
feat(windows): Set .qri-ref as hidden in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dustmop committed Sep 10, 2019
1 parent 2415505 commit 6d71d48
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fsi/fsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,11 @@ func (fsi *FSI) getRepoRef(refStr string) (ref repo.DatasetRef, err error) {
}

func writeLinkFile(dir, linkstr string) error {
dir = filepath.Join(dir, QriRefFilename)
return ioutil.WriteFile(dir, []byte(linkstr), os.ModePerm)
filepath := filepath.Join(dir, QriRefFilename)
if err := ioutil.WriteFile(filepath, []byte(linkstr), os.ModePerm); err != nil {
return err
}
return setFileHidden(filepath)
}

func removeLinkFile(dir string) error {
Expand Down
18 changes: 18 additions & 0 deletions fsi/set_file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// +build !windows

package fsi

import (
"fmt"
"path/filepath"
"strings"
)

// setFileHidden ensures the filename begins with a dot. Other OSes may do more
func setFileHidden(path string) error {
basename := filepath.Base(path)
if !strings.HasPrefix(basename, ".") {
return fmt.Errorf("hidden files must begin with \".\"")
}
return nil
}
21 changes: 21 additions & 0 deletions fsi/set_file_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package fsi

import (
"fmt"
"path/filepath"
"strings"
"syscall"
)

// setFileHidden sets the hidden attribute on the given file. Windows specific functionality
func setFileHidden(path string) error {
basename := filepath.Base(path)
if !strings.HasPrefix(basename, ".") {
return fmt.Errorf("hidden files must begin with \".\"")
}
filenamePtr, err := syscall.UTF16PtrFromString(path)
if err != nil {
return err
}
return syscall.SetFileAttributes(filenamePtr, syscall.FILE_ATTRIBUTE_HIDDEN)
}

0 comments on commit 6d71d48

Please sign in to comment.