Skip to content

Commit b347945

Browse files
committed
Use placeholder for all symlinks.
1 parent 777dbcf commit b347945

1 file changed

Lines changed: 9 additions & 21 deletions

File tree

extractor.go

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -248,37 +248,25 @@ func (e *Extractor) Tar(ctx context.Context, body io.Reader, location string, re
248248
}
249249

250250
func (e *Extractor) extractSymlinks(ctx context.Context, symlinks []*link) error {
251-
var placeholders []*link
252-
// remover, removeSupported := e.FS.(FSRemover)
253-
254251
for _, symlink := range symlinks {
255252
select {
256253
case <-ctx.Done():
257254
return errors.New("interrupted")
258255
default:
259256
}
260257

261-
// If the symlink pointer is clean make the symlink straighaway
262-
if clean := filepath.Clean(symlink.Name); !strings.Contains(clean, "..") && !filepath.IsAbs(clean) {
263-
_ = e.FS.Remove(symlink.Path)
264-
if err := e.FS.Symlink(symlink.Name, symlink.Path); err != nil {
265-
return errors.Annotatef(err, "Create link %s", symlink.Path)
266-
}
267-
} else {
268-
// Otherwise make a placeholder and replace it after unpacking everything
269-
_ = e.FS.Remove(symlink.Path)
270-
f, err := e.FS.OpenFile(symlink.Path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, os.FileMode(0666))
271-
if err != nil {
272-
return fmt.Errorf("creating symlink placeholder %s: %w", symlink.Path, err)
273-
}
274-
if err := f.Close(); err != nil {
275-
return fmt.Errorf("creating symlink placeholder %s: %w", symlink.Path, err)
276-
}
277-
placeholders = append(placeholders, symlink)
258+
// Make a placeholder and replace it after unpacking everything
259+
_ = e.FS.Remove(symlink.Path)
260+
f, err := e.FS.OpenFile(symlink.Path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, os.FileMode(0666))
261+
if err != nil {
262+
return fmt.Errorf("creating symlink placeholder %s: %w", symlink.Path, err)
263+
}
264+
if err := f.Close(); err != nil {
265+
return fmt.Errorf("creating symlink placeholder %s: %w", symlink.Path, err)
278266
}
279267
}
280268

281-
for _, symlink := range placeholders {
269+
for _, symlink := range symlinks {
282270
select {
283271
case <-ctx.Done():
284272
return errors.New("interrupted")

0 commit comments

Comments
 (0)