Skip to content
Permalink
Browse files Browse the repository at this point in the history
Remove file before io write file
  • Loading branch information
zachhuff386 committed Aug 31, 2020
1 parent 15aee03 commit 89f8c99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion service/profile/profile.go
Expand Up @@ -214,6 +214,7 @@ func (p *Profile) write() (pth string, err error) {

pth = filepath.Join(rootDir, p.Id)

_ = os.Remove(pth)
err = ioutil.WriteFile(pth, []byte(p.Data), os.FileMode(0600))
if err != nil {
err = &WriteError{
Expand Down Expand Up @@ -261,6 +262,7 @@ func (p *Profile) writeUp() (pth string, err error) {
panic("profile: Not implemented")
}

_ = os.Remove(pth)
err = ioutil.WriteFile(pth, []byte(script), os.FileMode(0755))
if err != nil {
err = &WriteError{
Expand Down Expand Up @@ -308,6 +310,7 @@ func (p *Profile) writeDown() (pth string, err error) {
panic("profile: Not implemented")
}

_ = os.Remove(pth)
err = ioutil.WriteFile(pth, []byte(script), os.FileMode(0755))
if err != nil {
err = &WriteError{
Expand All @@ -327,6 +330,7 @@ func (p *Profile) writeBlock() (pth string, err error) {

pth = filepath.Join(rootDir, p.Id+"-block.sh")

_ = os.Remove(pth)
err = ioutil.WriteFile(pth, []byte(blockScript), os.FileMode(0755))
if err != nil {
err = &WriteError{
Expand Down Expand Up @@ -468,6 +472,7 @@ func (p *Profile) writeAuth() (pth string, err error) {

pth = filepath.Join(rootDir, p.Id+".auth")

_ = os.Remove(pth)
err = ioutil.WriteFile(pth, []byte(username+"\n"+password+"\n"),
os.FileMode(0600))
if err != nil {
Expand Down Expand Up @@ -511,6 +516,7 @@ func (p *Profile) writeConfWgLinux() (pth string, err error) {

pth = filepath.Join(rootDir, p.Id+".key")

_ = os.Remove(pth)
err = ioutil.WriteFile(
pth,
[]byte(p.PrivateKeyWg+"\n"),
Expand Down Expand Up @@ -599,7 +605,7 @@ func (p *Profile) writeConfWgQuick(data *WgConf) (pth string, err error) {

pth = filepath.Join(rootDir, p.Iface+".conf")

os.Remove(pth)
_ = os.Remove(pth)
err = ioutil.WriteFile(
pth,
[]byte(output.String()),
Expand Down
1 change: 1 addition & 0 deletions service/utils/utils.go
Expand Up @@ -914,6 +914,7 @@ func PidInit() (err error) {
}
}

_ = os.Remove(pth)
err = ioutil.WriteFile(
pth,
[]byte(strconv.Itoa(os.Getpid())),
Expand Down

0 comments on commit 89f8c99

Please sign in to comment.