mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
refactor: name dirs by what they hold, trim exports (#692)
Bare dir now always means a user data dir, so the snapshot root, the export listing, and the keys.json kind get their own words; names used only inside their package are no longer exported.
This commit is contained in:
1 parent
2e7ee3c69f
commit
a7741eaab2
40 files changed
+242
-256
No files matched your search
+13
-13
@@ -14,16 +14,16 @@ import (
|
||||
)
|
||||
|
||||
type Writer struct {
|
||||
dir string
|
||||
format Format
|
||||
zip bool
|
||||
files map[category.Category]*categoryFile
|
||||
failed bool
|
||||
out Output
|
||||
dir string
|
||||
format Format
|
||||
zip bool
|
||||
files map[category.Category]*categoryFile
|
||||
failed bool
|
||||
listing Listing
|
||||
}
|
||||
|
||||
// Output is what a clean Close left in the output dir: each category file in category order, and the zip with --zip.
|
||||
type Output struct {
|
||||
// Listing is what a clean Close left in the output dir: each category file in category order, and the zip with --zip.
|
||||
type Listing struct {
|
||||
Dir string
|
||||
Files []File
|
||||
ZipName string
|
||||
@@ -82,7 +82,7 @@ func (w *Writer) write(dataCategory category.Category, records []record.Record)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close completes the files even after a failed Write, so they keep what was written; only a clean run fills Output.
|
||||
// Close completes the files even after a failed Write, so they keep what was written; only a clean run fills Listing.
|
||||
func (w *Writer) Close() error {
|
||||
var (
|
||||
errs []error
|
||||
@@ -106,15 +106,15 @@ func (w *Writer) Close() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
w.out = Output{Dir: w.dir, Files: files}
|
||||
w.listing = Listing{Dir: w.dir, Files: files}
|
||||
if w.zip {
|
||||
return w.writeZip()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *Writer) Output() Output {
|
||||
return w.out
|
||||
func (w *Writer) Listing() Listing {
|
||||
return w.listing
|
||||
}
|
||||
|
||||
// writeZip removes the loose files only after the zip is in place, so a failure leaves every one of them where it was.
|
||||
@@ -133,7 +133,7 @@ func (w *Writer) writeZip() error {
|
||||
return fmt.Errorf("zip: remove %s: %w", name, err)
|
||||
}
|
||||
}
|
||||
w.out.ZipName = zipName
|
||||
w.listing.ZipName = zipName
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ func TestClose_AfterFailedWriteKeepsEarlierFiles(t *testing.T) {
|
||||
var cookies []record.Cookie
|
||||
readJSON(t, filepath.Join(dir, "cookie.json"), &cookies)
|
||||
assert.Empty(t, cookies)
|
||||
assert.Zero(t, writer.Output(), "a failed run lists nothing")
|
||||
assert.Zero(t, writer.Listing(), "a failed run lists nothing")
|
||||
}
|
||||
|
||||
func TestClose_OutputListsTheFilesInCategoryOrder(t *testing.T) {
|
||||
@@ -128,7 +128,7 @@ func TestClose_OutputListsTheFilesInCategoryOrder(t *testing.T) {
|
||||
}))
|
||||
require.NoError(t, writer.Close())
|
||||
|
||||
assert.Equal(t, Output{Dir: dir, Files: []File{{Name: "password.json", Count: 2}, {Name: "history.json", Count: 1}}}, writer.Output())
|
||||
assert.Equal(t, Listing{Dir: dir, Files: []File{{Name: "password.json", Count: 2}, {Name: "history.json", Count: 1}}}, writer.Listing())
|
||||
}
|
||||
|
||||
// TestClose_ZipLeavesOtherFilesAlone packs only this run's files; the rest of the directory is not the writer's.
|
||||
@@ -158,7 +158,7 @@ func TestClose_ZipOutputNamesTheArchive(t *testing.T) {
|
||||
require.NoError(t, writer.Write(category.Password, []record.Record{&record.Login{URL: "https://a.example"}}))
|
||||
require.NoError(t, writer.Close())
|
||||
|
||||
assert.Equal(t, Output{Dir: dir, Files: []File{{Name: "password.csv", Count: 1}}, ZipName: "results.zip"}, writer.Output())
|
||||
assert.Equal(t, Listing{Dir: dir, Files: []File{{Name: "password.csv", Count: 1}}, ZipName: "results.zip"}, writer.Listing())
|
||||
}
|
||||
|
||||
// TestClose_ZipIsOwnerOnly gives the zip the category files' owner-only mode, since it holds the same records.
|
||||
|
||||
Reference in new issue
Block a user