Unity-Technologies / Unity-Technologies/UnityDataTools

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

未关闭 适合新手
#138 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug
主要语言
C#
星标
821
派生
71
平均合并
3 小时 13 分钟
30 天内合并 PR
9

描述

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.

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 AnalyzerTool.Analyze 中 CollectFiles() 之后的位置开始,检查当前无文件路径如何到达数据库创建和最终化处理。在那里添加无文件处理,决定是否与 #115 中的消息共用措辞,并验证当没有输入文件匹配时,现有的 -o 数据库不会被创建或截断。

由索引模型根据 Issue 内容生成。

评估

技术栈
csharp, sqlite
领域
cli, database
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
活跃
描述清晰度
基本清楚
新手友好度
75/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。