Unity-Technologies / Unity-Technologies/UnityDataTools

analyze truncates an existing -o database when the input matches no files

Offen Anfängerfreundlich
#138 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug
Vorherrschende Sprache
C#
Sterne
821
Forks
71
Ø Merge
3 Std. 13 Min.
Gemergte PRs (30 T.)
9

Beschreibung

When the input paths match no files at all, analyze still creates the output database before
discovering there is nothing to do. SQLiteWriter.Begin truncates the file (File.WriteAllBytes)
and runs the full schema init, the run then finds zero files, and the (now empty) database is
deleted.

The destructive part is the truncation. A mistyped path is enough:

UnityDataTool analyze C:/typo/not-a-real-path -o important.db

important.db is a previous, valid analysis. The command prints
Warning: path not found, skipping: C:/typo/not-a-real-path, truncates important.db anyway, and
(since #115) deletes it. The old content is gone either way — this behaviour predates #115, which
only changed what is left behind afterwards.

Nothing needs to touch the filesystem in this case. A check before the database is created, e.g.
after CollectFiles() in AnalyzerTool.Analyze:

if (files.Count == 0)
{
    Console.Error.WriteLine("Error: the input paths matched no files to analyze.");
    return 1;
}

avoids creating or truncating anything, and skips the schema init and finalize work that is
currently thrown away.

Points to decide:

  • This introduces a second "nothing was analyzed" message alongside the one added in #115. They
    could share wording.
  • It also makes an existing database at -o survive this class of failure, while a run where every
    file failed still deletes it. That difference is defensible (the file is only removed once its
    content has already been destroyed) but it should be a deliberate choice.

Found while reviewing the fix for #115; left out of that PR to keep it to a single failure path.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie in AnalyzerTool.Analyze an der Stelle nach CollectFiles() und überprüfen Sie, wie der Pfad ohne Dateien derzeit zur Datenbankerstellung und -finalisierung gelangt. Fügen Sie dort die Behandlung für keine Dateien hinzu, entscheiden Sie, ob die Formulierung mit der Meldung aus #115 geteilt werden soll, und stellen Sie sicher, dass eine vorhandene -o-Datenbank nicht erstellt oder abgeschnitten wird, wenn keine Eingabedateien übereinstimmen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp, sqlite
Bereich
cli, database
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
75/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.