Commit 517985a
committed
archive: create implied parents for directory entries
Tar archives are not required to contain headers for every parent
directory. A directory entry can therefore itself have implied parents.
For example, an archive may contain:
etc/dnf/
etc/dnf/dnf.conf
without containing an entry for `etc/`.
Create implied parent directories regardless of the type of the final
entry. The existing root-parent check still prevents attempting to
create a parent for top-level entries.
This restores the effective behavior from before go-archive v0.2.1.
The original implementation normalized `hdr.Name` with
`filepath.Clean`, then used a trailing path separator as an apparent
root check.[1] Its comments described this as an "is-root check" and
"Not the root directory".
Because `filepath.Clean` removes trailing separators from non-root
paths, a directory entry such as `etc/dnf/` became `etc/dnf` before
reaching the check. Its implied parent, `etc`, was therefore created.
The filesystem root `/` retained its trailing separator and was skipped;
`.` and `./` entered the block but resulted in a harmless check of the
already existing extraction root.
The code was later moved into the `createImpliedDirectories` helper.[2]
That extraction separated the trailing-separator check from the earlier
`filepath.Clean` call, obscuring that directory entries had already lost
their trailing separator before reaching the check.
Commit e45dc89 then replaced the ineffective trailing-separator check
with `hdr.Typeflag != tar.TypeDir`.[3] Although this appeared to correct
the directory detection, it changed the effective behavior: implied
parents were no longer created when the final entry was itself a
directory.
Both files and directories may have parents implied by their paths.
Remove the entry-type check and rely on the existing `parent == "." ||
parent == ""` guard to skip the extraction root.
[1]: moby/moby@a4868e2
[2]: 29b0f33
[3]: e45dc89
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>1 parent 1c23372 commit 517985a
2 files changed
Lines changed: 60 additions & 55 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1034 | 1034 | | |
1035 | 1035 | | |
1036 | 1036 | | |
1037 | | - | |
1038 | | - | |
1039 | | - | |
1040 | | - | |
1041 | | - | |
1042 | | - | |
1043 | | - | |
1044 | | - | |
1045 | | - | |
1046 | | - | |
1047 | | - | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
1048 | 1059 | | |
1049 | | - | |
1050 | | - | |
1051 | | - | |
1052 | | - | |
1053 | | - | |
1054 | | - | |
1055 | | - | |
1056 | | - | |
1057 | | - | |
1058 | | - | |
1059 | | - | |
1060 | | - | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
1061 | 1064 | | |
1062 | | - | |
1063 | | - | |
1064 | | - | |
1065 | | - | |
1066 | | - | |
1067 | 1065 | | |
1068 | | - | |
1069 | | - | |
1070 | | - | |
1071 | | - | |
1072 | | - | |
1073 | | - | |
1074 | | - | |
1075 | | - | |
1076 | | - | |
1077 | | - | |
1078 | | - | |
1079 | | - | |
1080 | | - | |
1081 | | - | |
| 1066 | + | |
1082 | 1067 | | |
1083 | 1068 | | |
1084 | 1069 | | |
1085 | | - | |
1086 | | - | |
1087 | | - | |
1088 | | - | |
1089 | | - | |
| 1070 | + | |
| 1071 | + | |
1090 | 1072 | | |
1091 | | - | |
1092 | | - | |
1093 | | - | |
1094 | | - | |
1095 | | - | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
1096 | 1085 | | |
1097 | 1086 | | |
1098 | 1087 | | |
1099 | | - | |
1100 | | - | |
1101 | | - | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
1102 | 1099 | | |
1103 | 1100 | | |
1104 | 1101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
93 | 101 | | |
94 | 102 | | |
95 | 103 | | |
| |||
0 commit comments