Skip to content

Commit 7f3001f

Browse files
committed
Fixed issue generating git status info for untract directories
1 parent b0c24a1 commit 7f3001f

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

pkg/archive/bundle.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,26 @@ func parseGitStatusLine(line string) (GitFileStatus, error) {
209209
}
210210

211211
if computeHash {
212-
file, err := os.Open(path)
213-
if err == nil {
214-
defer file.Close()
212+
fileStat, err := os.Stat(path)
213+
if err != nil {
214+
slog.Warn("Unable to stat file to compute SHA256 hash", "path", path, "error", err)
215+
return GitFileStatus{}, fmt.Errorf("failed to stat file '%s': %w", path, err)
216+
}
215217

216-
hasher := sha256.New()
217-
if _, err := io.Copy(hasher, file); err != nil {
218-
return GitFileStatus{}, fmt.Errorf("failed to compute SHA256 hash for file '%s': %w", path, err)
218+
if !fileStat.IsDir() {
219+
file, err := os.Open(path)
220+
if err == nil {
221+
defer file.Close()
222+
223+
hasher := sha256.New()
224+
if _, err := io.Copy(hasher, file); err != nil {
225+
return GitFileStatus{}, fmt.Errorf("failed to compute SHA256 hash for file '%s': %w", path, err)
226+
}
227+
fileSha256 = hex.EncodeToString(hasher.Sum([]byte{}))
228+
slog.Debug("file SHA256 hash computed", "path", path, "hash", fileSha256)
229+
} else {
230+
slog.Warn("Unable to open file to compute SHA256 hash", "path", path, "error", err)
219231
}
220-
fileSha256 = hex.EncodeToString(hasher.Sum([]byte{}))
221-
slog.Debug("file SHA256 hash computed", "path", path, "hash", fileSha256)
222-
} else {
223-
slog.Warn("Unable to open file to compute SHA256 hash", "path", path, "error", err)
224232
}
225233
}
226234

0 commit comments

Comments
 (0)