Skip to content

Commit

Permalink
Merge pull request #879 from TRON-US/fix-reset-path-issue-2-release
Browse files Browse the repository at this point in the history
fix: daemon not restarting after reset path.
  • Loading branch information
Eric Chen authored Jan 11, 2021
2 parents 02ed17f + 0f1f066 commit 86e6633
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions core/commands/storage/path/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import (
)

const (
defaultPath = "~/.btfs"
properties = ".btfs.properties"
BtfsPathKey = "BTFS_PATH"
defaultPath = "~/.btfs"
properties = ".btfs.properties"
BtfsPathKey = "BTFS_PATH"
BtfsPathFlag = "BTFS_PATH_FLAG"
)

var (
Expand Down Expand Up @@ -164,7 +165,12 @@ storage location, a specified path as a parameter need to be passed.
return fmt.Errorf("Not enough disk space, expect: ge %v bytes, actual: %v bytes",
promisedStorageSize, usage.Free)
}
go DoRestart(true)
go func() {
if e := os.Unsetenv(BtfsPathFlag); e != nil {
log.Error(e)
}
DoRestart(true)
}()
return nil
},
}
Expand Down Expand Up @@ -484,16 +490,18 @@ func CheckDirEmpty(dirname string) bool {
func SetEnvVariables() {
if CheckExist(PropertiesFileName) {
btfsPath = ReadProperties(PropertiesFileName)
btfsPath = strings.Replace(btfsPath, " ", "", -1)
btfsPath = strings.Replace(btfsPath, "\n", "", -1)
btfsPath = strings.Replace(btfsPath, "\r", "", -1)
btfsPath = strings.Trim(btfsPath, " \n\r")
if btfsPath != "" {
newPath := btfsPath
_, b := os.LookupEnv(BtfsPathKey)
_, b := os.LookupEnv(BtfsPathFlag)
if !b {
err := os.Setenv(BtfsPathKey, newPath)
if err != nil {
log.Errorf("cannot set env variable of BTFS_PATH: [%v] \n", err)
} else {
if err := os.Setenv(BtfsPathFlag, "T"); err != nil {
log.Error(err)
}
}
}
}
Expand Down

0 comments on commit 86e6633

Please sign in to comment.