Skip to content

Commit

Permalink
fix windows paths and permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
guumaster committed Mar 24, 2020
1 parent ec22b89 commit d60e04e
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.vscode
dist
hostctl
hostctl.exe
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func init() {
defaultHostsFile := "/etc/hosts"

if runtime.GOOS == "windows" {
defaultHostsFile = `C:\Windows\System32\Drivers\etc\hosts`
defaultHostsFile = `C:/Windows/System32/Drivers/etc/hosts`
}

envHostFile := os.Getenv("HOSTCTL_FILE")
Expand Down
2 changes: 1 addition & 1 deletion pkg/host/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func add(n *hostFile, opts *commonAddOptions) error {
}
currData.profiles[opts.Profile] = append(currData.profiles[opts.Profile], n.profiles["default"]...)

dstFile, err := os.OpenFile(opts.Dst, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0644)
dstFile, err := os.OpenFile(opts.Dst, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/host/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Disable(dst, profile string) error {
disableProfile(h, profile)
}

dstFile, err := os.OpenFile(dst, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0644)
dstFile, err := os.OpenFile(dst, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/host/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Enable(dst, profile string) error {
enableProfile(h, profile)
}

dstFile, err := os.OpenFile(dst, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0644)
dstFile, err := os.OpenFile(dst, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/host/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Remove(dst, profile string) error {
delete(h.profiles, profile)
}

dstFile, err := os.OpenFile(dst, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0644)
dstFile, err := os.OpenFile(dst, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644)
if err != nil {
return err
}
Expand Down

0 comments on commit d60e04e

Please sign in to comment.