Skip to content

Commit

Permalink
#141 [SL] - Change wahay config path on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
steffano0 committed Jan 23, 2025
1 parent ae802e4 commit df23aa7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
16 changes: 8 additions & 8 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (cs *ConfigSuite) Test_DetectPersistance_setsPersistentModeToFalseWhenFileD
err := os.MkdirAll(wahayDir, 0755)
c.Assert(err, IsNil)

defer gostub.New().Stub(&XdgConfigHome, func() string { return tempDir }).Reset()
defer gostub.New().Stub(&SystemConfigDir, func() string { return tempDir }).Reset()

ac := New()
filename, err := ac.DetectPersistence()
Expand All @@ -66,7 +66,7 @@ func (cs *ConfigSuite) Test_DetectPersistance_setsPersistentModeToTrueWhenFileEx
c.Assert(err, IsNil)
configFile.Close()

defer gostub.New().Stub(&XdgConfigHome, func() string { return tempDir }).Reset()
defer gostub.New().Stub(&SystemConfigDir, func() string { return tempDir }).Reset()

ac := New()
filename, err := ac.DetectPersistence()
Expand Down Expand Up @@ -180,7 +180,7 @@ func (cs *ConfigSuite) Test_getRealConfigFile_returnsEncryptedFile(c *C) {
c.Assert(err, IsNil)
file.Close()

defer gostub.New().Stub(&XdgConfigHome, func() string { return tempDir }).Reset()
defer gostub.New().Stub(&SystemConfigDir, func() string { return tempDir }).Reset()

a := &ApplicationConfig{}

Expand All @@ -204,7 +204,7 @@ func (cs *ConfigSuite) Test_getRealConfigFile_returnsUnencryptedFile(c *C) {
c.Assert(err, IsNil)
file.Close()

defer gostub.New().Stub(&XdgConfigHome, func() string { return tempDir }).Reset()
defer gostub.New().Stub(&SystemConfigDir, func() string { return tempDir }).Reset()

a := &ApplicationConfig{}

Expand All @@ -223,7 +223,7 @@ func (cs *ConfigSuite) Test_getRealConfigFile_returnsEmptyStringWhenFileDoesNotE
err := os.MkdirAll(wahayDir, 0755)
c.Assert(err, IsNil)

defer gostub.New().Stub(&XdgConfigHome, func() string { return tempDir }).Reset()
defer gostub.New().Stub(&SystemConfigDir, func() string { return tempDir }).Reset()

a := &ApplicationConfig{}

Expand Down Expand Up @@ -396,7 +396,7 @@ func (cs *ConfigSuite) Test_doAfterSave_addFunctionToList(c *C) {

func (cs *ConfigSuite) Test_EnsureDestination_createsEncryptedConfigFile(c *C) {
tempDir := c.MkDir()
defer gostub.New().Stub(&XdgConfigHome, func() string { return tempDir }).Reset()
defer gostub.New().Stub(&SystemConfigDir, func() string { return tempDir }).Reset()

a := &ApplicationConfig{
filename: "",
Expand All @@ -412,7 +412,7 @@ func (cs *ConfigSuite) Test_EnsureDestination_createsEncryptedConfigFile(c *C) {

func (cs *ConfigSuite) Test_EnsureDestination_createsUnencryptedConfigFile(c *C) {
tempDir := c.MkDir()
defer gostub.New().Stub(&XdgConfigHome, func() string { return tempDir }).Reset()
defer gostub.New().Stub(&SystemConfigDir, func() string { return tempDir }).Reset()

a := &ApplicationConfig{
filename: "",
Expand All @@ -428,7 +428,7 @@ func (cs *ConfigSuite) Test_EnsureDestination_createsUnencryptedConfigFile(c *C)

func (cs *ConfigSuite) Test_EnsureDestination_changesFileSuffixToAValidEncryptedSuffix(c *C) {
tempDir := c.MkDir()
defer gostub.New().Stub(&XdgConfigHome, func() string { return tempDir }).Reset()
defer gostub.New().Stub(&SystemConfigDir, func() string { return tempDir }).Reset()

a := &ApplicationConfig{
filename: "config.json",
Expand Down
5 changes: 0 additions & 5 deletions config/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ func TorDir() string {
return filepath.Join(Dir(), "tor")
}

// SystemConfigDir returns the application data directory, valid on both windows and posix systems
func SystemConfigDir() string {
return XdgConfigHome()
}

// RemoveAll removes a directory and it's children
func RemoveAll(dir string) error {
return os.RemoveAll(dir)
Expand Down
5 changes: 4 additions & 1 deletion config/os_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ func IsWindows() bool {
}

// SystemDataDir points to the function that gets the data directory for this system
var SystemDataDir = XdgDataHome
var (
SystemDataDir = XdgDataHome
SystemConfigDir = XdgConfigHome
)

func localHome() string {
u, e := user.Current()
Expand Down
5 changes: 4 additions & 1 deletion config/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ func appdataFolderPath() string {
}

// SystemDataDir points to the function that gets the data directory for this system
var SystemDataDir = appdataFolderPath
var (
SystemDataDir = appdataFolderPath
SystemConfigDir = appdataFolderPath
)

func firstEnvironmentVariable(vs ...string) string {
for _, v := range vs {
Expand Down

0 comments on commit df23aa7

Please sign in to comment.