Skip to content

Commit

Permalink
fix: create symlinks if unarchived files are symlinks (aquaproj#3433)
Browse files Browse the repository at this point in the history
* fix: create symlinks if unarchived files are symlinks

* refactor: ignore a lint error
  • Loading branch information
suzuki-shunsuke authored Jan 6, 2025
1 parent ecf84ff commit bb1bc5d
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions pkg/unarchive/archives.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@ func (h *handler) HandleFile(_ context.Context, f archives.FileInfo) error {
return nil
}

// if f.LinkTarget != "" {
// return nil
// }
if f.LinkTarget != "" {
if f.Mode()&os.ModeSymlink != 0 {
if err := os.Symlink(f.LinkTarget, dstPath); err != nil {
logerr.WithError(h.logE, err).WithFields(logrus.Fields{
"link_target": f.LinkTarget,
"link_dest": dstPath,
}).Warn("create a symlink")
return nil
}
}
return nil
}

reader, err := f.Open()
if err != nil {
Expand Down Expand Up @@ -77,17 +86,23 @@ func (h *handler) Unarchive(ctx context.Context, _ *logrus.Entry, src *File) err
if err != nil {
return fmt.Errorf("get a temporary file path: %w", err)
}
return h.unarchive(ctx, tempFilePath)
if err := h.unarchive(ctx, src.Filename, tempFilePath); err != nil {
return logerr.WithFields(err, logrus.Fields{ //nolint:wrapcheck
"archived_file": tempFilePath,
"archived_filename": src.Filename,
})
}
return nil
}

func (h *handler) unarchive(ctx context.Context, file string) error {
func (h *handler) unarchive(ctx context.Context, fileName, file string) error {
archiveFile, err := h.fs.Open(file)
if err != nil {
return fmt.Errorf("open a files: %w", err)
}
defer archiveFile.Close()

format, input, err := archives.Identify(ctx, file, archiveFile)
format, input, err := archives.Identify(ctx, fileName, archiveFile)
if err != nil {
return fmt.Errorf("identify the format: %w", err)
}
Expand Down

0 comments on commit bb1bc5d

Please sign in to comment.