Skip to content

Commit d88da96

Browse files
revert the syslinks
1 parent c003c99 commit d88da96

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

utils/extract.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ func ExtractTarGz(archive *os.File, targetDir string) error {
3131
return fmt.Errorf("failed to set target directory permissions: %w", err)
3232
}
3333

34+
// Create a map to store symlinks for later creation
35+
symlinks := make(map[string]string)
36+
3437
handler := func(ctx context.Context, f archiver.File) error {
3538
path := filepath.Join(targetDir, f.NameInArchive)
3639

@@ -44,6 +47,12 @@ func ExtractTarGz(archive *os.File, targetDir string) error {
4447
}
4548

4649
case false:
50+
// if is a symlink, store it for later
51+
if f.LinkTarget != "" {
52+
symlinks[path] = f.LinkTarget
53+
return nil
54+
}
55+
4756
parentDir := filepath.Dir(path)
4857
if err := os.MkdirAll(parentDir, constants.DefaultDirPerms); err != nil {
4958
return fmt.Errorf("failed to create parent directory %s: %w", parentDir, err)
@@ -92,6 +101,22 @@ func ExtractTarGz(archive *os.File, targetDir string) error {
92101
return fmt.Errorf("failed to extract archive: %w", err)
93102
}
94103

104+
// Create symlinks after all files have been extracted
105+
for path, target := range symlinks {
106+
// Remove any existing file/symlink
107+
os.Remove(path)
108+
109+
// Ensure parent directory exists
110+
if err := os.MkdirAll(filepath.Dir(path), constants.DefaultDirPerms); err != nil {
111+
return fmt.Errorf("failed to create parent directory for symlink %s: %w", path, err)
112+
}
113+
114+
// Create the symlink
115+
if err := os.Symlink(target, path); err != nil {
116+
return fmt.Errorf("failed to create symlink %s -> %s: %w", path, target, err)
117+
}
118+
}
119+
95120
return nil
96121
}
97122

@@ -124,6 +149,15 @@ func ExtractZip(zipPath string, targetDir string) error {
124149
}
125150

126151
case false:
152+
// if is a symlink
153+
if f.LinkTarget != "" {
154+
os.Remove(path)
155+
if err := os.Symlink(f.LinkTarget, path); err != nil {
156+
return fmt.Errorf("failed to create symlink %s -> %s: %w", path, f.LinkTarget, err)
157+
}
158+
return nil
159+
}
160+
127161
parentDir := filepath.Dir(path)
128162
if err := os.MkdirAll(parentDir, constants.DefaultDirPerms); err != nil {
129163
return fmt.Errorf("failed to create parent directory %s: %w", parentDir, err)

0 commit comments

Comments
 (0)