Skip to content

Commit 6a7adab

Browse files
authored
Fix reading config directory (#193)
1 parent cfc4a07 commit 6a7adab

File tree

4 files changed

+24
-45
lines changed

4 files changed

+24
-45
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog
22

3+
### Version [2.1.1](https://github.com/majd/ipatool/releases/tag/v2.1.1)
4+
5+
- Fixed an issue when creating the config directory for the tool.
6+
37
### Version [2.1.0](https://github.com/majd/ipatool/releases/tag/v2.1.0)
48

59
- Implemented `Lookup` API.

cmd/common.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,16 @@ func initWithCommand(cmd *cobra.Command) {
131131
Machine: dependencies.Machine,
132132
})
133133

134-
util.Must("", createConfigDirectory())
134+
util.Must("", createConfigDirectory(dependencies.OS, dependencies.Machine))
135135
}
136136

137137
// createConfigDirectory creates the configuration directory for the CLI tool, if needed.
138-
func createConfigDirectory() error {
139-
configDirectoryPath := filepath.Join(dependencies.Machine.HomeDirectory(), ConfigDirectoryName)
140-
_, err := dependencies.OS.Stat(configDirectoryPath)
138+
func createConfigDirectory(os operatingsystem.OperatingSystem, machine machine.Machine) error {
139+
configDirectoryPath := filepath.Join(machine.HomeDirectory(), ConfigDirectoryName)
140+
_, err := os.Stat(configDirectoryPath)
141141

142-
if err != nil && dependencies.OS.IsNotExist(err) {
143-
err = dependencies.OS.MkdirAll(configDirectoryPath, 0700)
142+
if err != nil && os.IsNotExist(err) {
143+
err = os.MkdirAll(configDirectoryPath, 0700)
144144
if err != nil {
145145
return fmt.Errorf("failed to create config directory: %w", err)
146146
}
+13-37
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package operatingsystem
22

33
import (
4-
"fmt"
54
"os"
65
)
76

@@ -27,60 +26,37 @@ func (operatingSystem) Getenv(key string) string {
2726
return os.Getenv(key)
2827
}
2928

29+
// nolint:wrapcheck
3030
func (operatingSystem) Stat(name string) (os.FileInfo, error) {
31-
info, err := os.Stat(name)
32-
if err != nil {
33-
return nil, fmt.Errorf("failed to describe file '%s': %w", name, err)
34-
}
35-
36-
return info, nil
31+
return os.Stat(name)
3732
}
3833

34+
// nolint:wrapcheck
3935
func (operatingSystem) Getwd() (string, error) {
40-
wd, err := os.Getwd()
41-
if err != nil {
42-
return "", fmt.Errorf("failed to get current directory: %w", err)
43-
}
44-
45-
return wd, nil
36+
return os.Getwd()
4637
}
4738

39+
// nolint:wrapcheck
4840
func (operatingSystem) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) {
49-
file, err := os.OpenFile(name, flag, perm)
50-
if err != nil {
51-
return nil, fmt.Errorf("failed to open file '%s': %w", name, err)
52-
}
53-
54-
return file, nil
41+
return os.OpenFile(name, flag, perm)
5542
}
5643

44+
// nolint:wrapcheck
5745
func (operatingSystem) Remove(name string) error {
58-
err := os.Remove(name)
59-
if err != nil {
60-
return fmt.Errorf("failed to remove file '%s': %w", name, err)
61-
}
62-
63-
return nil
46+
return os.Remove(name)
6447
}
6548

49+
// nolint:wrapcheck
6650
func (operatingSystem) IsNotExist(err error) bool {
6751
return os.IsNotExist(err)
6852
}
6953

54+
// nolint:wrapcheck
7055
func (operatingSystem) MkdirAll(path string, perm os.FileMode) error {
71-
err := os.MkdirAll(path, perm)
72-
if err != nil {
73-
return fmt.Errorf("failed to create directory '%s': %w", path, err)
74-
}
75-
76-
return nil
56+
return os.MkdirAll(path, perm)
7757
}
7858

59+
// nolint:wrapcheck
7960
func (operatingSystem) Rename(oldPath, newPath string) error {
80-
err := os.Rename(oldPath, newPath)
81-
if err != nil {
82-
return fmt.Errorf("failed to rename '%s' to '%s': %w", oldPath, newPath, err)
83-
}
84-
85-
return nil
61+
return os.Rename(oldPath, newPath)
8662
}

pkg/util/operatingsystem/operatingsystem_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package operatingsystem
22

33
import (
4-
"errors"
54
"fmt"
65
"io/fs"
76
"math/rand"
@@ -70,7 +69,7 @@ var _ = Describe("OperatingSystem", func() {
7069
Expect(err).ToNot(HaveOccurred())
7170

7271
_, err = sut.Stat(file.Name())
73-
Expect(os.IsNotExist(errors.Unwrap(err))).To(BeTrue())
72+
Expect(os.IsNotExist(err)).To(BeTrue())
7473
})
7574

7675
It("renames file", func() {

0 commit comments

Comments
 (0)