Skip to content

Commit

Permalink
fix: Add ModTime to fileListEntry and consider it when extracting
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Apr 18, 2024
1 parent dedc148 commit 164252d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
9 changes: 8 additions & 1 deletion embed_util/embedded_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io/fs"
"os"
"path/filepath"
"time"
)

type EmbeddedFiles struct {
Expand Down Expand Up @@ -128,7 +129,7 @@ func (e *EmbeddedFiles) copyEmbeddedFilesToTmp(embedFs fs.FS, fl *fileList) erro
if resolvedFle.Mode.Type() == existingSt.Mode().Type() {
if resolvedFle.Mode.IsDir() {
continue
} else if existingSt.Size() == resolvedFle.Size {
} else if existingSt.Size() == resolvedFle.Size && existingSt.ModTime().Unix() == resolvedFle.ModTime {
// unchanged
continue
}
Expand Down Expand Up @@ -176,6 +177,12 @@ func (e *EmbeddedFiles) copyEmbeddedFilesToTmp(embedFs fs.FS, fl *fileList) erro
if err != nil {
return err
}
if !resolvedFle.Mode.IsDir() {
err = os.Chtimes(path, time.Time{}, time.Unix(resolvedFle.ModTime, 0))
if err != nil {
return err
}
}
}

return nil
Expand Down
16 changes: 10 additions & 6 deletions embed_util/file_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type fileList struct {
type fileListEntry struct {
Name string `json:"name"`
Size int64 `json:"size"`
ModTime int64 `json:"modTime"`
Mode fs.FileMode `json:"perm"`
Symlink string `json:"symlink,omitempty"`
Compressed bool `json:"compressed,omitempty"`
Expand Down Expand Up @@ -48,9 +49,10 @@ func buildFileListFromDir(dir string) (*fileList, error) {
}

fle := fileListEntry{
Name: relPath,
Size: info.Size(),
Mode: info.Mode(),
Name: relPath,
Size: info.Size(),
ModTime: info.ModTime().Unix(),
Mode: info.Mode(),
}

if info.Mode().Type() == fs.ModeSymlink {
Expand Down Expand Up @@ -92,15 +94,17 @@ func buildFileListFromFs(embedFs fs.FS) (*fileList, error) {
}

fle := fileListEntry{
Name: path,
Size: info.Size(),
Mode: info.Mode() | 0o600,
Name: path,
Size: info.Size(),
ModTime: info.ModTime().Unix(),
Mode: info.Mode() | 0o600,
}

if info.Mode().Type() == fs.ModeSymlink {
return fmt.Errorf("symlink not supported in buildFileListFromFs")
} else if info.Mode().IsDir() {
fle.Size = 0
fle.ModTime = 0
}

fl.Files = append(fl.Files, fle)
Expand Down

0 comments on commit 164252d

Please sign in to comment.