[mirror] Scalable static site server for Git forges (like GitHub Pages)

Ensure leading directories always exist in manifest

When extracting from an archive it is possible the leading directories
are not part of the archive. Add them to the manifest as otherwise the
behaviour of "index.html" varies depending how the archive was created.

authored by David Leadbeater and committed by whitequark.org 04729c1f 121f5570

Changed files
+21
src
+7
src/extract.go
··· 145 145 return nil, UnresolvedRefError{missing} 146 146 } 147 147 148 + // Ensure parent directories exist for all entries. 149 + EnsureLeadingDirectories(manifest) 150 + 148 151 logc.Printf(ctx, 149 152 "reuse: %s recycled, %s transferred\n", 150 153 datasize.ByteSize(dataBytesRecycled).HR(), ··· 226 229 return nil, UnresolvedRefError{missing} 227 230 } 228 231 232 + // Ensure parent directories exist for all entries. 233 + EnsureLeadingDirectories(manifest) 234 + 229 235 logc.Printf(ctx, 230 236 "reuse: %s recycled, %s transferred\n", 231 237 datasize.ByteSize(dataBytesRecycled).HR(), ··· 234 240 235 241 return manifest, nil 236 242 } 243 +
+14
src/manifest.go
··· 144 144 return fmt.Errorf("%s: %s", pathName, cause) 145 145 } 146 146 147 + // EnsureLeadingDirectories adds directory entries for any parent directories 148 + // that are implicitly referenced by files in the manifest but don't have 149 + // explicit directory entries. (This can be the case if an archive is created 150 + // via globs rather than including a whole directory.) 151 + func EnsureLeadingDirectories(manifest *Manifest) { 152 + for name := range manifest.Contents { 153 + for dir := path.Dir(name); dir != "." && dir != ""; dir = path.Dir(dir) { 154 + if _, exists := manifest.Contents[dir]; !exists { 155 + AddDirectory(manifest, dir) 156 + } 157 + } 158 + } 159 + } 160 + 147 161 func GetProblemReport(manifest *Manifest) []string { 148 162 var report []string 149 163 for _, problem := range manifest.Problems {