Skip to content

[#138] Do not truncate the output database when no input files match - #161

Merged
SkowronskiAndrew merged 1 commit into
Unity-Technologies:mainfrom
armadavalor:fix/analyze-no-input-keeps-db
Nov 19, 2026
Merged

SkowronskiAndrew merged 1 commit into
Unity-Technologies:mainfrom
armadavalor:fix/analyze-no-input-keeps-db

Conversation

@armadavalor

Copy link
Copy Markdown
Contributor

When the input paths match no files, analyze created the output database before finding out there was nothing to do. SQLiteWriter.Begin truncates the file, so a previous analysis at the -o path was lost.

This adds the files.Count == 0 check suggested in the issue. It runs after PrepareContentDirectoryInputs, because that step can add build history files to the input. The check runs before the database is opened, so it now prints Error: the input paths matched no files to analyze., returns 1, and leaves the file alone.

On the points the issue leaves open:

A mistyped path is already rejected by the ExistingOnly() validation on the paths argument, so the test covers the case that still gets through: an existing directory that contains no files (a --search-pattern that matches nothing takes the same path). Analyze_NoInputFiles_KeepsDatabaseOfPreviousRun builds a database, runs analyze on an empty folder with the same -o, and checks the exit code, the message, and that the database bytes are unchanged. It fails without the change.

dotnet test -c Release: Analyzer.Tests 67 passed, UnityFileSystem.Tests 442 passed (10 skipped), UnityDataTool.Tests 358 passed. Tested on Windows only.

Closes #138

…input files match

When the input paths match no files, analyze opened the output database
(truncating any existing one) before finding there was nothing to do.
Check for an empty input set before the database is created.

@SkowronskiAndrew SkowronskiAndrew left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution, I've reviewed and confirms this covers #138.
There is one other case, if there are files found but they are all ignored. But that is outside the scope of this bug, i will land this.

@SkowronskiAndrew
SkowronskiAndrew merged commit 8b8e0fe into Unity-Technologies:main Nov 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants