Name the database each command uses on stderr (closes #111)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
scan, report and trees now print one line on stderr before anything else, naming the database and whether its path is the default or comes from SFDUPES_DATABASE; scan also says when the file is new. report and trees print it before opening the database, so a missing-database error follows it. A relative path gets the working directory put in front of it, with its symlinks resolved as the kernel reports it, and is not cleaned: a ".." after a symlink names another file than the cleaned path does. README "Database" lists when scan writes each file. Unverified: the line on a terminal has no test of its own. Model: opus-5-5
This commit was merged in pull request #118.
This commit is contained in:
+38
-7
@@ -43,16 +43,47 @@ func openTestDB(t *testing.T) *sql.DB {
|
||||
}
|
||||
|
||||
func TestDatabasePath(t *testing.T) {
|
||||
t.Setenv(databaseEnv, "")
|
||||
|
||||
if got := databasePath(); got != defaultDatabasePath {
|
||||
t.Errorf("databasePath() = %q, want %q", got, defaultDatabasePath)
|
||||
// README §Database: SFDUPES_DATABASE when set and non-empty, the
|
||||
// default otherwise, with the working directory, its symlinks
|
||||
// resolved, put in front of a relative path. Nothing is cleaned, so
|
||||
// a ".." stays.
|
||||
dir, err := filepath.EvalSymlinks(t.TempDir())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Setenv(databaseEnv, "/custom/place.sqlite")
|
||||
t.Chdir(dir)
|
||||
|
||||
if got := databasePath(); got != "/custom/place.sqlite" {
|
||||
t.Errorf("databasePath() = %q, want the env override", got)
|
||||
fromEnv := "from " + databaseEnv
|
||||
cases := []struct {
|
||||
env, path, source string
|
||||
}{
|
||||
{"", defaultDatabasePath, "default"},
|
||||
{"/custom/place.sqlite", "/custom/place.sqlite", fromEnv},
|
||||
{"/custom/link/../place.sqlite", "/custom/link/../place.sqlite",
|
||||
fromEnv},
|
||||
{"sub/place.sqlite", dir + "/sub/place.sqlite", fromEnv},
|
||||
{"link/../place.sqlite", dir + "/link/../place.sqlite", fromEnv},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Setenv(databaseEnv, tc.env)
|
||||
|
||||
path, source, err := databasePath()
|
||||
if err != nil || path != tc.path || source != tc.source {
|
||||
t.Errorf("databasePath() with %s=%q = %q, %q, %v; want %q, %q",
|
||||
databaseEnv, tc.env, path, source, err, tc.path, tc.source)
|
||||
}
|
||||
}
|
||||
|
||||
// In the root directory the path gets one slash in front, not two.
|
||||
t.Chdir("/")
|
||||
t.Setenv(databaseEnv, "place.sqlite")
|
||||
|
||||
path, _, err := databasePath()
|
||||
if err != nil || path != "/place.sqlite" {
|
||||
t.Errorf("databasePath() in / = %q, %v; want %q",
|
||||
path, err, "/place.sqlite")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user