Skip to content

Commit

Permalink
fix(fsi): Remove references that have no path and no working directory.
Browse files Browse the repository at this point in the history
Merge pull request #1062 from qri-io/ref-no-paths
  • Loading branch information
dustmop authored Dec 18, 2019
2 parents e52c391 + f04981b commit f2ed024
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
28 changes: 28 additions & 0 deletions cmd/fsi_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,34 @@ func TestRemoveWorkingDirectory(t *testing.T) {
}
}

// Test that removing a directory before ever saving will remove the reference entirely
func TestRemoveWithoutAnyHistory(t *testing.T) {
run := NewFSITestRunner(t, "qri_test_remove_no_hist")
defer run.Delete()

workDir := run.CreateAndChdirToWorkDir("remove_no_hist")

// Init as a linked directory.
run.MustExec(t, "qri init --name remove_no_hist --format csv")

// Go up one directory
parentDir := filepath.Dir(workDir)
run.Must(t, os.Chdir(parentDir))

// Remove the directory
run.Must(t, os.RemoveAll(workDir))

// List will detect that the directory is no longer linked
run.MustExec(t, "qri list")

// List datasets, the removed directory is no longer linked
output := run.MustExec(t, "qri list --raw")
expect := "\n"
if diff := cmp.Diff(expect, output); diff != "" {
t.Errorf("unexpected (-want +got):\n%s", diff)
}
}

func parseRefFromSave(output string) string {
pos := strings.Index(output, "saved: ")
ref := output[pos+7:]
Expand Down
8 changes: 7 additions & 1 deletion lib/datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,14 @@ func (r *DatasetRequests) List(p *ListParams, res *[]repo.DatasetRef) error {
_, err := os.Stat(target)
if os.IsNotExist(err) {
ref.FSIPath = ""
if ref.Path == "" {
if err = r.node.Repo.DeleteRef(ref); err != nil {
log.Debugf("cannot delete ref for %q, err: %s", ref, err)
}
continue
}
if err = r.node.Repo.PutRef(ref); err != nil {
return err
log.Debugf("cannot put ref for %q, err: %s", ref, err)
}
}
}
Expand Down

0 comments on commit f2ed024

Please sign in to comment.