@@ -59,8 +59,8 @@ func isHttpURL(str string) bool {
59
59
return u .Scheme == "http" || u .Scheme == "https"
60
60
}
61
61
62
- // resolveFilePath expands the ~ in file paths to the user's home directory and converts relative paths to absolute paths.
63
- func resolveFilePath (path string ) (string , error ) {
62
+ // getAbsoluteFilePath expands the ~ in file paths to the user's home directory and converts relative paths to absolute paths.
63
+ func getAbsoluteFilePath (path string ) (string , error ) {
64
64
if path == "" {
65
65
return "" , nil
66
66
}
@@ -80,12 +80,12 @@ func resolveFilePath(path string) (string, error) {
80
80
81
81
// CreateSnapshot creates a snapshot of the database based on the provided configuration.
82
82
func (s * SnapshotService ) CreateSnapshot () error {
83
- resolvedFilePath , err := resolveFilePath (s .cfg .OutputFile )
83
+ absoluteFilePath , err := getAbsoluteFilePath (s .cfg .OutputFile )
84
84
if err != nil {
85
85
return errors .Wrap (err , fmt .Sprintf ("failed to resolve output file path '%s'" , s .cfg .OutputFile ))
86
86
}
87
87
88
- s .l .Sugar ().Debugw ("Resolved file paths " , zap .String ("Output" , resolvedFilePath ))
88
+ s .l .Sugar ().Debugw ("Absolute file path " , zap .String ("Output" , absoluteFilePath ))
89
89
90
90
if err := s .validateCreateSnapshotConfig (); err != nil {
91
91
return err
@@ -107,8 +107,8 @@ func (s *SnapshotService) CreateSnapshot() error {
107
107
108
108
s .l .Sugar ().Infow ("Successfully created snapshot" )
109
109
110
- outputHashFile := getHashName (resolvedFilePath )
111
- if err := saveOutputFileHash (resolvedFilePath , outputHashFile ); err != nil {
110
+ outputHashFile := getHashName (absoluteFilePath )
111
+ if err := saveOutputFileHash (absoluteFilePath , outputHashFile ); err != nil {
112
112
return errors .Wrap (err , fmt .Sprintf ("failed to save output file hash '%s'" , outputHashFile ))
113
113
}
114
114
@@ -122,7 +122,7 @@ func (s *SnapshotService) RestoreSnapshot() error {
122
122
s .tempFiles = s .tempFiles [:0 ] // Clear the tempFiles slice after cleanup
123
123
}()
124
124
125
- var resolvedFilePath string
125
+ var absoluteFilePath string
126
126
if isHttpURL (s .cfg .Input ) {
127
127
inputUrl := s .cfg .Input
128
128
@@ -152,28 +152,28 @@ func (s *SnapshotService) RestoreSnapshot() error {
152
152
}
153
153
s .tempFiles = append (s .tempFiles , inputFilePath )
154
154
155
- resolvedFilePath , err = resolveFilePath (inputFilePath )
155
+ absoluteFilePath , err = getAbsoluteFilePath (inputFilePath )
156
156
if err != nil {
157
157
return errors .Wrap (err , fmt .Sprintf ("failed to resolve input file path '%s'" , inputFilePath ))
158
158
}
159
159
} else {
160
160
var err error
161
- resolvedFilePath , err = resolveFilePath (s .cfg .Input )
161
+ absoluteFilePath , err = getAbsoluteFilePath (s .cfg .Input )
162
162
if err != nil {
163
163
return errors .Wrap (err , fmt .Sprintf ("failed to resolve input file path '%s'" , s .cfg .Input ))
164
164
}
165
165
}
166
166
167
- s .l .Sugar ().Debugw ("Resolved file path" , zap .String ("resolvedFilePath " , resolvedFilePath ))
167
+ s .l .Sugar ().Debugw ("absolute file path" , zap .String ("absoluteFilePath " , absoluteFilePath ))
168
168
169
169
// validate snapshot against the hash file
170
170
if s .cfg .VerifyInput {
171
- if err := validateInputFileHash (resolvedFilePath ); err != nil {
172
- return errors .Wrap (err , fmt .Sprintf ("input file hash validation failed for '%s'" , resolvedFilePath ))
171
+ if err := validateInputFileHash (absoluteFilePath ); err != nil {
172
+ return errors .Wrap (err , fmt .Sprintf ("input file hash validation failed for '%s'" , absoluteFilePath ))
173
173
}
174
174
s .l .Sugar ().Debugw ("Input file hash validated successfully" ,
175
- zap .String ("input" , resolvedFilePath ),
176
- zap .String ("inputHashFile" , getHashName (resolvedFilePath )),
175
+ zap .String ("input" , absoluteFilePath ),
176
+ zap .String ("inputHashFile" , getHashName (absoluteFilePath )),
177
177
)
178
178
}
179
179
@@ -182,7 +182,7 @@ func (s *SnapshotService) RestoreSnapshot() error {
182
182
return err
183
183
}
184
184
185
- restoreExec := restore .Exec (resolvedFilePath , pgcommands.ExecOptions {StreamPrint : false })
185
+ restoreExec := restore .Exec (absoluteFilePath , pgcommands.ExecOptions {StreamPrint : false })
186
186
if restoreExec .Error != nil {
187
187
s .l .Sugar ().Errorw ("Failed to restore from snapshot" ,
188
188
zap .Error (restoreExec .Error .Err ),
@@ -223,11 +223,11 @@ func (s *SnapshotService) setupSnapshotDump() (*pgcommands.Dump, error) {
223
223
if s .cfg .SchemaName != "" {
224
224
dump .Options = append (dump .Options , fmt .Sprintf ("--schema=%s" , s .cfg .SchemaName ))
225
225
}
226
- resolvedFilePath , err := resolveFilePath (s .cfg .OutputFile )
226
+ absoluteFilePath , err := getAbsoluteFilePath (s .cfg .OutputFile )
227
227
if err != nil {
228
228
return nil , errors .Wrap (err , fmt .Sprintf ("failed to resolve output file path '%s'" , s .cfg .OutputFile ))
229
229
}
230
- dump .SetFileName (resolvedFilePath )
230
+ dump .SetFileName (absoluteFilePath )
231
231
232
232
return dump , nil
233
233
}
0 commit comments