Skip to content

Commit

Permalink
ensure empty filenames are reported properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoisaiah committed Oct 11, 2024
1 parent 6820ad2 commit 9009742
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
10 changes: 10 additions & 0 deletions internal/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ type Change struct {
func (c *Change) AutoFixTarget(newTarget string) {
c.Target = newTarget
c.TargetPath = filepath.Join(c.BaseDir, c.Target)

// Ensure empty targets is reported as empty instead of as a dot
if c.TargetPath == "." {
c.TargetPath = ""
}

if c.Target == "" && c.TargetPath != "" {
c.TargetPath += "/"
}

c.Status = status.OK
}

Expand Down
2 changes: 2 additions & 0 deletions validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func checkEmptyFilenameConflict(
) (conflictDetected bool) {
if ctx.change.Target == "." || ctx.change.Target == "" {
conflictDetected = true

ctx.change.AutoFixTarget("")
ctx.change.Status = status.EmptyFilename

if ctx.autoFix {
Expand Down
20 changes: 12 additions & 8 deletions validate/validate_test/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ func validateTest(t *testing.T, cases []testutil.TestCase) {
ch.BaseDir,
ch.Source,
)
cases[i].Changes[j].TargetPath = filepath.Join(
ch.BaseDir,
ch.Target,
)

if cases[i].Changes[j].TargetPath == "" {
cases[i].Changes[j].TargetPath = filepath.Join(
ch.BaseDir,
ch.Target,
)
}
}
}

Expand Down Expand Up @@ -93,10 +96,11 @@ func TestValidate(t *testing.T) {
Name: "detect empty filename conflict",
Changes: file.Changes{
{
Source: "1984.pdf",
Target: "",
BaseDir: "ebooks",
Status: status.EmptyFilename,
Source: "1984.pdf",
Target: "",
TargetPath: "ebooks/",
BaseDir: "ebooks",
Status: status.EmptyFilename,
},
},
ConflictDetected: true,
Expand Down

0 comments on commit 9009742

Please sign in to comment.