Unity-Technologies / Unity-Technologies/UnityDataTools
analyze truncates an existing -o database when the input matches no files
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 821
- Forks
- 71
- Avg merge
- 3h 13m
- Merged PRs (30d)
- 9
Description
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
-osurvive 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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in AnalyzerTool.Analyze at the point after CollectFiles(), and review how the zero-file path currently reaches database creation and finalization. Add the no-files handling there, decide whether to share wording with the message from #115, and verify that an existing -o database is not created or truncated when no input files match.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sqlite
- Domain
- cli, database
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 75/100