Skip to content

bug: deep target file paths for consistent snapshots #631

@mrjoelkamp

Description

@mrjoelkamp

Issue

Deep target file paths, or file paths that are more than one subdirectory deep (e.g. <dir1>/<dir2>/file) fail to download due to the targetRemotePath being built wrong when using consistent snapshots.

Root Cause

Current state of the code uses strings.Cut() to parse the directory name from the file name. This works for target files that are only one directory deep (<subdir>/file.ext) because strings.Cut() splits the string on the first occurrence of the separator.

dirName, baseName, ok := strings.Cut(targetFilePath, "/")
if !ok {
// <hash>.<target-name>
targetRemotePath = fmt.Sprintf("%s.%s", hashes, dirName)
} else {
// <dir-prefix>/<hash>.<target-name>
targetRemotePath = fmt.Sprintf("%s/%s.%s", dirName, hashes, baseName)
}

For nested target file paths (<subdir1>/<subdir2>/file.ext) the targetRemotePath ends up being generated incorrectly since the first occurrence of / does not separate the directory from the file name.

When using consistent snapshots, this ends up making the path be <subdir1>/<hash>.<subdir2>/file.ext instead of <subdir1>/<subdir2>/<hash>.file.ext

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions