From 83bee231ad56a0a0b9000d66adc4c8486c54d5a5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 16 Sep 2026 12:20:17 +0000 Subject: [PATCH 1/7] Initial plan From a87ce2d5cfb0ef05db9725a1e826ba4bc7b88e42 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 16 Sep 2026 12:23:16 +0000 Subject: [PATCH 2/7] dub: update ae to 0.0.3870 Co-authored-by: CyberShadow <160894+CyberShadow@users.noreply.github.com> --- dub-lock.json | 4 +-- dub.sdl | 2 +- dub.selections.json | 6 ++-- source/btdu/impexp.d | 65 +++++++++++++++++++++++++++++++++----------- source/btdu/paths.d | 20 ++++++++++---- 5 files changed, 70 insertions(+), 27 deletions(-) diff --git a/dub-lock.json b/dub-lock.json index 97205eb..a145180 100644 --- a/dub-lock.json +++ b/dub-lock.json @@ -1,8 +1,8 @@ { "dependencies": { "ae": { - "version": "0.0.3701", - "sha256": "0vf458cvr8mmvjr87g2i6yhn7yyz1cg4lbixf62b9qnszd88j2q2" + "version": "0.0.3870", + "sha256": "0p9gnygb0lq07wday1mmsh1b8ag43h73arjgzjfjxg0y3y1mrk8c" }, "btrfs": { "version": "0.0.21", diff --git a/dub.sdl b/dub.sdl index cd2d31e..347af2a 100644 --- a/dub.sdl +++ b/dub.sdl @@ -5,7 +5,7 @@ targetType "executable" toolchainRequirements frontend=">=2.097" -dependency "ae" version="==0.0.3701" +dependency "ae" version="==0.0.3870" dependency "btrfs" version="~>0.0.21" dependency "ncurses" version="~>1.0.0" dependency "emsi_containers" version="==0.9.0" diff --git a/dub.selections.json b/dub.selections.json index 054b640..67e0dad 100644 --- a/dub.selections.json +++ b/dub.selections.json @@ -1,9 +1,9 @@ { "fileVersion": 1, "versions": { - "ae": "0.0.3701", + "ae": "0.0.3870", "btrfs": "0.0.21", - "ncurses": "1.0.0", - "emsi_containers": "0.9.0" + "emsi_containers": "0.9.0", + "ncurses": "1.0.0" } } diff --git a/source/btdu/impexp.d b/source/btdu/impexp.d index cebef85..c41f43d 100644 --- a/source/btdu/impexp.d +++ b/source/btdu/impexp.d @@ -15,7 +15,7 @@ import core.lifetime : move; import ae.sys.data; import ae.sys.datamm; -import ae.utils.json; +import ae.utils.serialization.json; import btrfs.c.ioctl : btrfs_ioctl_fs_info_args; @@ -91,8 +91,19 @@ void importData(string path) // JSON format // ============================================================================ -/// Serialized -struct SerializedState +/// Serialized import state +struct ImportedSerializedState +{ + bool expert; + @JSONOptional bool physical; + string fsPath; + @JSONOptional string fsid; /// UUID formatted as "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + ulong totalSize; + BrowserPath.SerializedForm root; +} + +/// Serialized export state +struct ExportedSerializedState { bool expert; @JSONOptional bool physical; @@ -121,20 +132,36 @@ private typeof(btrfs_ioctl_fs_info_args.fsid) parseFsid(string s) /// Load and parse an exported JSON file. /// Returns the parsed state structure. /// The memory-mapped file is stored in the output parameter to keep it alive. -private SerializedState loadExportFile(string path, out Data mmapData) +private ImportedSerializedState loadExportFile(string path, out Data mmapData) { mmapData = mapFile(path, MmMode.read); auto json = cast(string)mmapData.unsafeContents; debug importing = true; scope(exit) debug importing = false; - return json.jsonParse!SerializedState(); + return json.jsonParse!ImportedSerializedState(); } /// Keep memory-mapped files alive, as directory names may reference them private __gshared Data importMmapData; private __gshared Data compareMmapData; +private struct JsonOutputAdapter(Output) +{ + Output output; + + void put(T...)(T args) + { + static foreach (arg; args) + output.put(arg); + } + + string get() + { + return null; + } +} + bool isJsonFormat(string path) { import std.file : read; @@ -158,7 +185,10 @@ void importJson(string path) fsPath = s.fsPath; fsid = parseFsid(s.fsid); totalSize = s.totalSize; - move(*s.root, browserRoot); + debug importing = true; + scope(exit) debug importing = false; + auto importedRoot = BrowserPath.fromJSON(s.root); + move(importedRoot, browserRoot); browserRoot.resetParents(); imported = true; @@ -194,7 +224,10 @@ private void importCompareJson(string path) compareTotalSize = s.totalSize; compareFsid = parseFsid(s.fsid); // Note: we don't set fsPath from compare - keep current fsPath - move(*s.root, compareRoot); + debug importing = true; + scope(exit) debug importing = false; + auto importedCompareRoot = BrowserPath.fromJSON(s.root); + move(importedCompareRoot, compareRoot); compareRoot.resetParents(); compareMode = true; @@ -221,7 +254,7 @@ void exportData(string path, ExportFormat fmt = ExportFormat.json) private void exportJson(string path) { - SerializedState s; + ExportedSerializedState s; s.expert = expert; s.physical = physical; s.fsPath = fsPath; @@ -230,14 +263,14 @@ private void exportJson(string path) s.root = browserRootPtr; alias LockingBinaryWriter = typeof(File.lockingBinaryWriter()); - alias JsonFileSerializer = CustomJsonSerializer!(JsonWriter!LockingBinaryWriter); - - { - JsonFileSerializer j; - auto file = path is null ? stdout : File(path, "wb"); - j.writer.output = file.lockingBinaryWriter; - j.put(s); - } + alias OutputAdapter = JsonOutputAdapter!LockingBinaryWriter; + + auto file = path is null ? stdout : File(path, "wb"); + OutputAdapter output; + output.output = file.lockingBinaryWriter; + JsonWriter!OutputAdapter writer; + writer.output = output; + JsonCustomSerializer.Impl!Object.read(&writer, s); } // ============================================================================ diff --git a/source/btdu/paths.d b/source/btdu/paths.d index 6cebd4c..ca291cb 100644 --- a/source/btdu/paths.d +++ b/source/btdu/paths.d @@ -1286,15 +1286,24 @@ struct BrowserPath @JSONOptional Nullable!bool mark; @JSONOptional ulong[string] seenAs; // Map: path -> sample count + SerializedForm[] children; + } + + struct ExportSerializedForm + { + string name; + SerializedForm.SerializedData data; + @JSONOptional Nullable!bool mark; + @JSONOptional ulong[string] seenAs; // Map: path -> sample count BrowserPath*[] children; } - SerializedForm toJSON() + ExportSerializedForm toJSON() { import std.conv : to; import btdu.state : exportSeenAs; - SerializedForm s; + ExportSerializedForm s; s.name = this.name[]; for (auto p = firstChild; p; p = p.nextSibling) s.children ~= p; @@ -1323,10 +1332,11 @@ struct BrowserPath import std.conv : to; auto p = BrowserPath(null, NameString(s.name)); - foreach_reverse (child; s.children) + foreach_reverse (ref child; s.children) { - child.nextSibling = p.firstChild; - p.firstChild = child; + auto parsedChild = growAllocator.make!BrowserPath(BrowserPath.fromJSON(child)); + parsedChild.nextSibling = p.firstChild; + p.firstChild = parsedChild; } auto aggData = p.ensureAggregateData(); static foreach (sampleType; EnumMembers!SampleType) From ef30105801820bab7d838d21c6218aa58fee09c4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 16 Sep 2026 12:24:40 +0000 Subject: [PATCH 3/7] btdu.impexp: use toJson for export Co-authored-by: CyberShadow <160894+CyberShadow@users.noreply.github.com> --- source/btdu/impexp.d | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/source/btdu/impexp.d b/source/btdu/impexp.d index c41f43d..f70604a 100644 --- a/source/btdu/impexp.d +++ b/source/btdu/impexp.d @@ -146,22 +146,6 @@ private ImportedSerializedState loadExportFile(string path, out Data mmapData) private __gshared Data importMmapData; private __gshared Data compareMmapData; -private struct JsonOutputAdapter(Output) -{ - Output output; - - void put(T...)(T args) - { - static foreach (arg; args) - output.put(arg); - } - - string get() - { - return null; - } -} - bool isJsonFormat(string path) { import std.file : read; @@ -262,15 +246,8 @@ private void exportJson(string path) s.totalSize = totalSize; s.root = browserRootPtr; - alias LockingBinaryWriter = typeof(File.lockingBinaryWriter()); - alias OutputAdapter = JsonOutputAdapter!LockingBinaryWriter; - - auto file = path is null ? stdout : File(path, "wb"); - OutputAdapter output; - output.output = file.lockingBinaryWriter; - JsonWriter!OutputAdapter writer; - writer.output = output; - JsonCustomSerializer.Impl!Object.read(&writer, s); + auto file = path is null ? stdout : File(path, "w"); + file.write(toJson(s)); } // ============================================================================ From 0b912cf5568aedd83cc8d8129998de1ad4059547 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 16 Sep 2026 12:25:02 +0000 Subject: [PATCH 4/7] btdu.impexp: keep JSON export binary Co-authored-by: CyberShadow <160894+CyberShadow@users.noreply.github.com> --- source/btdu/impexp.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/btdu/impexp.d b/source/btdu/impexp.d index f70604a..79cc730 100644 --- a/source/btdu/impexp.d +++ b/source/btdu/impexp.d @@ -246,7 +246,7 @@ private void exportJson(string path) s.totalSize = totalSize; s.root = browserRootPtr; - auto file = path is null ? stdout : File(path, "w"); + auto file = path is null ? stdout : File(path, "wb"); file.write(toJson(s)); } From 15643587fa493cb580509ab452366ad2670bd0f6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 16 Sep 2026 12:25:27 +0000 Subject: [PATCH 5/7] btdu.impexp: write JSON as raw bytes Co-authored-by: CyberShadow <160894+CyberShadow@users.noreply.github.com> --- source/btdu/impexp.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/btdu/impexp.d b/source/btdu/impexp.d index 79cc730..9070ab9 100644 --- a/source/btdu/impexp.d +++ b/source/btdu/impexp.d @@ -247,7 +247,7 @@ private void exportJson(string path) s.root = browserRootPtr; auto file = path is null ? stdout : File(path, "wb"); - file.write(toJson(s)); + file.rawWrite(toJson(s)); } // ============================================================================ From f6bca656b61e7c73869d92597fe84e0d0a271820 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 16 Sep 2026 12:26:05 +0000 Subject: [PATCH 6/7] btdu.impexp: restore binary JSON stream Co-authored-by: CyberShadow <160894+CyberShadow@users.noreply.github.com> --- source/btdu/impexp.d | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/source/btdu/impexp.d b/source/btdu/impexp.d index 9070ab9..6efce0e 100644 --- a/source/btdu/impexp.d +++ b/source/btdu/impexp.d @@ -146,6 +146,25 @@ private ImportedSerializedState loadExportFile(string path, out Data mmapData) private __gshared Data importMmapData; private __gshared Data compareMmapData; +private struct JsonOutputAdapter(Output) +{ + Output output; + + void put(T...)(T args) + { + static foreach (arg; args) + output.put(arg); + } + + auto get() + { + static if (__traits(compiles, output.get())) + return output.get(); + else + return ""; + } +} + bool isJsonFormat(string path) { import std.file : read; @@ -246,8 +265,15 @@ private void exportJson(string path) s.totalSize = totalSize; s.root = browserRootPtr; + alias LockingBinaryWriter = typeof(File.lockingBinaryWriter()); + alias OutputAdapter = JsonOutputAdapter!LockingBinaryWriter; + auto file = path is null ? stdout : File(path, "wb"); - file.rawWrite(toJson(s)); + OutputAdapter output; + output.output = file.lockingBinaryWriter; + JsonWriter!OutputAdapter writer; + writer.output = output; + JsonCustomSerializer.Impl!Object.read(&writer, s); } // ============================================================================ From d6908745fb2c033bbd38837ae5b073b9107531a5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 16 Sep 2026 12:26:28 +0000 Subject: [PATCH 7/7] btdu.impexp: gate adapter get support Co-authored-by: CyberShadow <160894+CyberShadow@users.noreply.github.com> --- source/btdu/impexp.d | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/btdu/impexp.d b/source/btdu/impexp.d index 6efce0e..43a680a 100644 --- a/source/btdu/impexp.d +++ b/source/btdu/impexp.d @@ -156,12 +156,12 @@ private struct JsonOutputAdapter(Output) output.put(arg); } - auto get() + static if (__traits(compiles, { Output output; output.get(); })) { - static if (__traits(compiles, output.get())) + auto get() + { return output.get(); - else - return ""; + } } }