Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
xxdk-wasm
Merge requests
!18
Something went wrong on our end
XX-4272 / Purge
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
XX-4272 / Purge
XX-4272/purge
into
release
Overview
0
Commits
15
Pipelines
0
Changes
2
Merged
Jono Wenger
requested to merge
XX-4272/purge
into
release
2 years ago
Overview
0
Commits
15
Pipelines
0
Changes
2
Expand
Add function to clear all persistent storage used by wasm.
0
0
Merge request reports
Viewing commit
5ddc38cb
Prev
Next
Show latest version
2 files
+
68
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
5ddc38cb
Add Purge function to clear all storage used by wasm
· 5ddc38cb
Jono Wenger
authored
2 years ago
wasm/purge.go
+
65
−
0
Options
@@ -7,9 +7,74 @@
package
wasm
import
(
"github.com/hack-pad/go-indexeddb/idb"
"github.com/pkg/errors"
"gitlab.com/elixxir/xxdk-wasm/creds"
"gitlab.com/elixxir/xxdk-wasm/utils"
"sync/atomic"
"syscall/js"
)
// NumClientsRunning is an atomic that tracks the current number of Cmix
// followers that have been started. Every time one is started, this counter
// must be incremented and every time one is stopped, it must be decremented.
//
// This variable is an atomic. Only access it with atomic functions
var
NumClientsRunning
uint64
// Purge clears all local storage and indexedDb databases saved by this WASM
// binary. All Cmix followers must be closed and the user's password is
// required.
//
// Warning: This deletes all storage local to the webpage running this WASM.
// Only use if you want to destroy everything.
//
// Parameters:
// - args[0] - Storage directory path (string).
// - args[1] - Password used for storage (Uint8Array).
//
// Returns:
// - Throws a TypeError if the password is incorrect or if not all Cmix
// followers have been stopped.
func
Purge
(
_
js
.
Value
,
args
[]
js
.
Value
)
interface
{}
{
// Check the password
if
!
creds
.
VerifyPassword
(
js
.
Value
{},
[]
js
.
Value
{
args
[
1
]})
.
(
bool
)
{
utils
.
Throw
(
utils
.
TypeError
,
errors
.
New
(
"invalid password"
))
return
nil
}
// Verify all Cmix followers are stopped
if
n
:=
atomic
.
LoadUint64
(
&
NumClientsRunning
);
n
!=
0
{
utils
.
Throw
(
utils
.
TypeError
,
errors
.
Errorf
(
"%d Cmix followers running"
,
n
))
return
nil
}
// Get all indexedDb database names
databaseList
,
err
:=
utils
.
GetIndexedDbList
()
if
err
!=
nil
{
utils
.
Throw
(
utils
.
TypeError
,
errors
.
Errorf
(
"failed to get list of indexedDb database names: %+v"
,
err
))
return
nil
}
// Delete each database
for
_
,
dbName
:=
range
databaseList
{
_
,
err
=
idb
.
Global
()
.
DeleteDatabase
(
dbName
)
if
err
!=
nil
{
utils
.
Throw
(
utils
.
TypeError
,
errors
.
Errorf
(
"failed to delete indexedDb database %q: %+v"
,
dbName
,
err
))
return
nil
}
}
// Clear WASM local storage and EKV
ls
:=
utils
.
GetLocalStorage
()
ls
.
ClearWASM
()
ls
.
ClearPrefix
(
args
[
0
]
.
String
())
return
nil
}
Loading