--output iterated all 156k active Blogs rows and printed a "does not exist or is not set" skip line for each, which is nearly every blog in the crawl registry -- only the few hundred downloaded locally ever have a folder. The signal was buried in six figures of noise. GetAllBlogsWithTTFolderPath now selects only active blogs carrying a non-empty path, so --output processes export targets and nothing else. When none exist it says so once, names the database it read, points at --updatepaths, and returns non-zero instead of reporting success. A stored path this machine cannot see is now reported separately from an unset one, with the path shown, because the two are fixed in different places. Paths are trimmed before Directory.Exists, which stray whitespace in a .tumblr FileDownloadLocation would otherwise defeat. Both writers counted optimistically. UpdateBlogPathsRunner printed its per-blog success line and incremented its total from the metadata file parsing, never checking whether the UPDATE matched a row; LegacyPostsDbImporter counted a blog as copied even when the legacy TTFolderPath was NULL. Either could report full success having written nothing -- which is consistent with TL.db holding zero populated paths across all 156,492 active blogs despite 20,679 posts having merged. SetBlogTTFolderPath now returns whether a row changed, and both callers report written / already-correct / no-matching-row separately. Verified against a throwaway database: no-paths case, export case (stale .txt rotated to .bak, per-PostType files, date-sorted), missing-folder case, --updatepaths honest counts, and an idempotent rerun reporting already-correct. Co-Authored-By: Claude Opus 5 <[email protected]>
104 lines
4.2 KiB
C#
104 lines
4.2 KiB
C#
using System.Text.Json;
|
|
|
|
namespace URLNotesGrabberCORE
|
|
{
|
|
// Port of ThreeTxtFileHelper/UpdateBlogPaths.cs. Reads .tumblr / .tmblrpriv metadata
|
|
// files from a root\Index folder and populates Blogs.TTFolderPath in TL.db.
|
|
public static class UpdateBlogPathsRunner
|
|
{
|
|
public static int Run(string rootPath)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(rootPath))
|
|
{
|
|
Console.WriteLine("UpdateBlogPaths: rootPath is required.");
|
|
return 1;
|
|
}
|
|
|
|
DataAccess.EnsureTTFileHelperColumnsExist();
|
|
|
|
string indexPath = Path.Combine(rootPath, "Index");
|
|
if (!Directory.Exists(indexPath))
|
|
{
|
|
Console.WriteLine($"Index folder not found at: {indexPath}");
|
|
return 1;
|
|
}
|
|
|
|
Console.WriteLine($"Scanning Index folder: {indexPath}");
|
|
|
|
var blogFiles = Directory.GetFiles(indexPath, "*.tumblr")
|
|
.Concat(Directory.GetFiles(indexPath, "*.tmblrpriv"))
|
|
.ToList();
|
|
|
|
Console.WriteLine($"Found {blogFiles.Count} blog metadata files");
|
|
|
|
int updatedCount = 0;
|
|
int unchangedCount = 0;
|
|
int noLocationCount = 0;
|
|
int noRowCount = 0;
|
|
int errorCount = 0;
|
|
|
|
foreach (var blogFile in blogFiles)
|
|
{
|
|
try
|
|
{
|
|
string blogName = Path.GetFileNameWithoutExtension(blogFile);
|
|
string jsonContent = File.ReadAllText(blogFile);
|
|
using JsonDocument doc = JsonDocument.Parse(jsonContent);
|
|
JsonElement root = doc.RootElement;
|
|
|
|
if (root.TryGetProperty("FileDownloadLocation", out JsonElement locationElement))
|
|
{
|
|
string? fileDownloadLocation = locationElement.GetString()?.Trim();
|
|
if (!string.IsNullOrWhiteSpace(fileDownloadLocation))
|
|
{
|
|
// Report the database's answer, not the fact that the file parsed.
|
|
if (DataAccess.SetBlogTTFolderPath(blogName, fileDownloadLocation))
|
|
{
|
|
updatedCount++;
|
|
Console.WriteLine($"Updated {blogName}: {fileDownloadLocation}");
|
|
}
|
|
else if (DataAccess.BlogExists(blogName))
|
|
{
|
|
unchangedCount++;
|
|
}
|
|
else
|
|
{
|
|
noRowCount++;
|
|
Console.WriteLine($"No Blogs row named '{blogName}' -- path not stored (name may differ in case)");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
noLocationCount++;
|
|
Console.WriteLine($"Empty FileDownloadLocation in {blogFile}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
noLocationCount++;
|
|
Console.WriteLine($"No FileDownloadLocation found in {blogFile}");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errorCount++;
|
|
Console.WriteLine($"Error processing {blogFile}: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
Console.WriteLine($"\n========== UpdateBlogPaths summary ==========");
|
|
Console.WriteLine($"Metadata files: {blogFiles.Count}");
|
|
Console.WriteLine($"TTFolderPath written: {updatedCount}");
|
|
Console.WriteLine($"Already correct: {unchangedCount}");
|
|
Console.WriteLine($"No FileDownloadLocation: {noLocationCount}");
|
|
Console.WriteLine($"No matching blog row: {noRowCount}");
|
|
Console.WriteLine($"Errors: {errorCount}");
|
|
|
|
int stored = DataAccess.CountBlogsWithTTFolderPath();
|
|
Console.WriteLine($"\nBlogs now holding a TTFolderPath: {stored}");
|
|
|
|
return errorCount == 0 ? 0 : 2;
|
|
}
|
|
}
|
|
}
|