Skip to content

Commit

Permalink
Resolve GH-7 VFS Upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord of Scripts committed Sep 20, 2024
1 parent 44dbbda commit 50210ff
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 19 deletions.
6 changes: 5 additions & 1 deletion browsers/chromium/chromium.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ func (c *ChromiumCleaner) eraseProfile() error {

// (b) we are going to clean the profile's top level
var filter cmn.IDirCleaner
filter = cmn.NewDirCleaner(c.ProfileRoot, c.sizeMode, c.doDryRun)
if !c.doDryRun {
filter = cmn.NewDirCleaner(c.ProfileRoot, c.sizeMode, false)
} else {
filter = cmn.NewDirCleanerDryVFS(c.ProfileRoot, c.sizeMode, c.logx)
}

// (c) except these important profile items
err := filter.CleanUp(ProfileExceptions)
Expand Down
6 changes: 5 additions & 1 deletion browsers/firefox/firefox.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,11 @@ func (c *FirefoxCleaner) eraseProfile() error {
// (b) we are going to clean the profile's top level
fmt.Printf("%s DirCleanerRoot %s\n", cmn.ThisLocation(1), c.ProfileRoot)
var filter cmn.IDirCleaner
filter = cmn.NewDirCleaner(c.ProfileRoot, c.sizeMode, c.doDryRun)
if !c.doDryRun {
filter = cmn.NewDirCleaner(c.ProfileRoot, c.sizeMode, false)
} else {
filter = cmn.NewDirCleanerDryVFS(c.ProfileRoot, c.sizeMode, c.logx)
}

// (c) except these important profile items
err := filter.CleanUp(FirefoxProfileExceptions)
Expand Down
27 changes: 22 additions & 5 deletions dircleaner_vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
"path/filepath"
"slices" // GO v1.18

"github.com/blang/vfs"
"github.com/lordofscripts/vfs"
"github.com/lordofscripts/vfs/bucketfs"
)

/* ----------------------------------------------------------------
Expand All @@ -34,6 +35,7 @@ type DirCleanerVFS struct {
cleanedSize int64
removedQty int
skippedQty int
sizeMode SizeMode
logx ILogger
vfs vfs.Filesystem
}
Expand All @@ -42,23 +44,38 @@ type DirCleanerVFS struct {
* C o n s t r u c t o r s
*-----------------------------------------------------------------*/

func NewDirCleanerVFS(fs vfs.Filesystem, root string, logger ...ILogger) *DirCleanerVFS {
const cName = "DirCleaner"
// NewDirCleanerVFS creates a new (recursive) directory cleaner instance with
// the selected Virtual File System instance.
func NewDirCleanerVFS(fs vfs.Filesystem, root string, sizing SizeMode, logger ...ILogger) *DirCleanerVFS {
const cName = "DirCleanerVFS"
var logCtx ILogger
if len(logger) == 0 {
logCtx = NewConditionalLogger(false, cName)
} else {
logCtx = logger[0].InheritAs(cName)
}
return &DirCleanerVFS{root, 0, 0, 0, logCtx, fs}
return &DirCleanerVFS{root, 0, 0, 0, sizing, logCtx, fs}
}

// NewDirCleanerDryVFS creates a new (recursive) directory cleaner instance with
// the Bit-Bucket Virtual File System in a mode that allows us to do a Dry Run.
// Note: This is equivalent to the other ctor. but creates the bucketfs internally
// before calling the default ctor.
func NewDirCleanerDryVFS(root string, sizing SizeMode, logger ...ILogger) *DirCleanerVFS {
fs := bucketfs.Create()
return NewDirCleanerVFS(fs, root, sizing, logger...)
}

/* ----------------------------------------------------------------
* M e t h o d s
*-----------------------------------------------------------------*/

// Stringer interface
func (d *DirCleanerVFS) String() string {
return fmt.Sprintf("DirCleaner %q del:%d skip:%d size:%d", d.Root, d.removedQty, d.skippedQty, d.cleanedSize)
return fmt.Sprintf("DirCleaner %q del:%d skip:%d size:%s", d.Root,
d.removedQty,
d.skippedQty,
ReportByteCount(d.cleanedSize, d.sizeMode))
}

func (d *DirCleanerVFS) CleanUp(exceptions []string) error {
Expand Down
2 changes: 1 addition & 1 deletion file_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"reflect"
"sync"

"github.com/blang/vfs"
"github.com/lordofscripts/vfs"
)

/* ----------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/lordofscripts/wipechromium
go 1.22.1

require (
github.com/blang/vfs v1.0.0
github.com/go-ini/ini v1.67.0
github.com/lordofscripts/vfs v1.3.0
)

require github.com/stretchr/testify v1.9.0 // indirect
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
github.com/blang/vfs v1.0.0 h1:AUZUgulCDzbaNjTRWEP45X7m/J10brAptZpSRKRZBZc=
github.com/blang/vfs v1.0.0/go.mod h1:jjuNUc/IKcRNNWC9NUCvz4fR9PZLPIKxEygtPs/4tSI=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/lordofscripts/vfs v1.2.1 h1:vlCGaG2V4onwfudNd2wHH+d85shIKu/zo6nInANhQ0k=
github.com/lordofscripts/vfs v1.2.1/go.mod h1:cSJ5rcrNGSFh3NtOZc/zEvoXU24IesjxRchBSjRGMxM=
github.com/lordofscripts/vfs v1.3.0 h1:XDanFPzFDJ30+SLKdwf4hvru1GstaRG4aYPQJVSdhIw=
github.com/lordofscripts/vfs v1.3.0/go.mod h1:cSJ5rcrNGSFh3NtOZc/zEvoXU24IesjxRchBSjRGMxM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
Expand Down
2 changes: 1 addition & 1 deletion sizemode.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

const (
SizeModeStd SizeMode = iota // full numeric size
SizeModeSI // Sistema Internacional: 1KB = 1000
SizeModeSI // Sistema Internacional: 1K = 1000
SizeModeIEC // Binary System: 1KB = 1024
)

Expand Down
8 changes: 4 additions & 4 deletions test/dircleaner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"path/filepath"
"testing"

"github.com/blang/vfs"
"github.com/blang/vfs/memfs"
"github.com/lordofscripts/vfs"
"github.com/lordofscripts/vfs/memfs"

"github.com/lordofscripts/wipechromium"
)
Expand Down Expand Up @@ -155,7 +155,7 @@ func Test_DirCleanerCache(t *testing.T) {
showVFS(mfs, CacheDir, false)
}

cleaner := wipechromium.NewDirCleanerVFS(mfs, CacheDir, logx)
cleaner := wipechromium.NewDirCleanerVFS(mfs, CacheDir, wipechromium.SizeModeSI, logx)
if err := cleaner.CleanUp(ExceptionsCache); err == nil {
fmt.Printf("Cache cleaned: %d\n%s\n", cleaner.CleanedSize(), cleaner)
if count := tallyTree(mfs, CacheDir); count != -1 && count < totalObjects {
Expand All @@ -182,7 +182,7 @@ func Test_DirCleanerData(t *testing.T) {
showVFS(mfs, DataDir, false)
}

cleaner := wipechromium.NewDirCleanerVFS(mfs, DataDir, logx)
cleaner := wipechromium.NewDirCleanerVFS(mfs, DataDir, wipechromium.SizeModeSI, logx)
if err := cleaner.CleanUp(ExceptionsData); err == nil {
fmt.Printf("Data cleaned: %d\n%s\n", cleaner.CleanedSize(), cleaner)
if count := tallyTree(mfs, DataDir); count != -1 && count < totalObjects {
Expand Down
4 changes: 2 additions & 2 deletions test/fileops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"reflect"
"testing"

"github.com/blang/vfs"
"github.com/blang/vfs/memfs"
"github.com/lordofscripts/vfs"
"github.com/lordofscripts/vfs/memfs"

cmn "github.com/lordofscripts/wipechromium"
)
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (
)

// NOTE: Change these values accordingly
var Version string = version{NAME, "0.4.0", statusReleased, 0}.String()
var Version string = version{NAME, "0.4.1", statusReleased, 0}.String()

/* ----------------------------------------------------------------
* T y p e s
Expand Down

0 comments on commit 50210ff

Please sign in to comment.