Skip to content

Commit 8237a2a

Browse files
authored
Fix issue 2601 (dont fail on empty /nix folder) (#2605)
## Summary Fix for #2601 ## How was it tested? 1. created empty /nix folder 2. devbox succeeds now installing nix ## Community Contribution License All community contributions in this pull request are licensed to the project maintainers under the terms of the [Apache 2 License](https://www.apache.org/licenses/LICENSE-2.0). By creating this pull request, I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the [Community Contribution License](https://github.com/jetify-com/opensource/blob/main/CONTRIBUTING.md#community-contribution-license).
1 parent dd069a4 commit 8237a2a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

internal/fileutil/fileutil.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ func Exists(path string) bool {
5151
return err == nil
5252
}
5353

54+
func IsDirEmpty(path string) bool {
55+
entries, err := os.ReadDir(path)
56+
if err != nil {
57+
return false
58+
}
59+
return len(entries) == 0
60+
}
61+
5462
// FileContains checks if a given file at 'path' contains the 'substring'
5563
func FileContains(path, substring string) (bool, error) {
5664
data, err := os.ReadFile(path)

internal/nix/install.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ func BinaryInstalled() bool {
2525
return cmdutil.Exists("nix")
2626
}
2727

28-
func dirExists() bool {
29-
return fileutil.Exists("/nix")
28+
func dirExistsAndIsNotEmpty() bool {
29+
dir := "/nix"
30+
return fileutil.Exists(dir) && !fileutil.IsDirEmpty(dir)
3031
}
3132

3233
var ensured = false
@@ -57,7 +58,7 @@ func EnsureNixInstalled(ctx context.Context, writer io.Writer, withDaemonFunc fu
5758
if BinaryInstalled() {
5859
return nil
5960
}
60-
if dirExists() {
61+
if dirExistsAndIsNotEmpty() {
6162
if _, err = SourceProfile(); err != nil {
6263
return err
6364
} else if BinaryInstalled() {

0 commit comments

Comments
 (0)