Skip to content

Commit

Permalink
resolved -> absolute wording for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendanCoughlan5 committed Feb 14, 2025
1 parent c0355ed commit d2f477c
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions pkg/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func isHttpURL(str string) bool {
return u.Scheme == "http" || u.Scheme == "https"
}

// resolveFilePath expands the ~ in file paths to the user's home directory and converts relative paths to absolute paths.
func resolveFilePath(path string) (string, error) {
// getAbsoluteFilePath expands the ~ in file paths to the user's home directory and converts relative paths to absolute paths.
func getAbsoluteFilePath(path string) (string, error) {
if path == "" {
return "", nil
}
Expand All @@ -80,12 +80,12 @@ func resolveFilePath(path string) (string, error) {

// CreateSnapshot creates a snapshot of the database based on the provided configuration.
func (s *SnapshotService) CreateSnapshot() error {
resolvedFilePath, err := resolveFilePath(s.cfg.OutputFile)
absoluteFilePath, err := getAbsoluteFilePath(s.cfg.OutputFile)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to resolve output file path '%s'", s.cfg.OutputFile))
}

s.l.Sugar().Debugw("Resolved file paths", zap.String("Output", resolvedFilePath))
s.l.Sugar().Debugw("Absolute file path", zap.String("Output", absoluteFilePath))

if err := s.validateCreateSnapshotConfig(); err != nil {
return err
Expand All @@ -107,8 +107,8 @@ func (s *SnapshotService) CreateSnapshot() error {

s.l.Sugar().Infow("Successfully created snapshot")

outputHashFile := getHashName(resolvedFilePath)
if err := saveOutputFileHash(resolvedFilePath, outputHashFile); err != nil {
outputHashFile := getHashName(absoluteFilePath)
if err := saveOutputFileHash(absoluteFilePath, outputHashFile); err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to save output file hash '%s'", outputHashFile))
}

Expand All @@ -122,7 +122,7 @@ func (s *SnapshotService) RestoreSnapshot() error {
s.tempFiles = s.tempFiles[:0] // Clear the tempFiles slice after cleanup
}()

var resolvedFilePath string
var absoluteFilePath string
if isHttpURL(s.cfg.Input) {
inputUrl := s.cfg.Input

Expand Down Expand Up @@ -152,28 +152,28 @@ func (s *SnapshotService) RestoreSnapshot() error {
}
s.tempFiles = append(s.tempFiles, inputFilePath)

resolvedFilePath, err = resolveFilePath(inputFilePath)
absoluteFilePath, err = getAbsoluteFilePath(inputFilePath)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to resolve input file path '%s'", inputFilePath))
}
} else {
var err error
resolvedFilePath, err = resolveFilePath(s.cfg.Input)
absoluteFilePath, err = getAbsoluteFilePath(s.cfg.Input)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to resolve input file path '%s'", s.cfg.Input))
}
}

s.l.Sugar().Debugw("Resolved file path", zap.String("resolvedFilePath", resolvedFilePath))
s.l.Sugar().Debugw("absolute file path", zap.String("absoluteFilePath", absoluteFilePath))

// validate snapshot against the hash file
if s.cfg.VerifyInput {
if err := validateInputFileHash(resolvedFilePath); err != nil {
return errors.Wrap(err, fmt.Sprintf("input file hash validation failed for '%s'", resolvedFilePath))
if err := validateInputFileHash(absoluteFilePath); err != nil {
return errors.Wrap(err, fmt.Sprintf("input file hash validation failed for '%s'", absoluteFilePath))
}
s.l.Sugar().Debugw("Input file hash validated successfully",
zap.String("input", resolvedFilePath),
zap.String("inputHashFile", getHashName(resolvedFilePath)),
zap.String("input", absoluteFilePath),
zap.String("inputHashFile", getHashName(absoluteFilePath)),
)
}

Expand All @@ -182,7 +182,7 @@ func (s *SnapshotService) RestoreSnapshot() error {
return err
}

restoreExec := restore.Exec(resolvedFilePath, pgcommands.ExecOptions{StreamPrint: false})
restoreExec := restore.Exec(absoluteFilePath, pgcommands.ExecOptions{StreamPrint: false})
if restoreExec.Error != nil {
s.l.Sugar().Errorw("Failed to restore from snapshot",
zap.Error(restoreExec.Error.Err),
Expand Down Expand Up @@ -223,11 +223,11 @@ func (s *SnapshotService) setupSnapshotDump() (*pgcommands.Dump, error) {
if s.cfg.SchemaName != "" {
dump.Options = append(dump.Options, fmt.Sprintf("--schema=%s", s.cfg.SchemaName))
}
resolvedFilePath, err := resolveFilePath(s.cfg.OutputFile)
absoluteFilePath, err := getAbsoluteFilePath(s.cfg.OutputFile)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to resolve output file path '%s'", s.cfg.OutputFile))
}
dump.SetFileName(resolvedFilePath)
dump.SetFileName(absoluteFilePath)

return dump, nil
}
Expand Down

0 comments on commit d2f477c

Please sign in to comment.