Skip to content

Commit

Permalink
Fixes #486 (#487)
Browse files Browse the repository at this point in the history
* Fixes #486

* Don't use a list in changelog

* Update CHANGELOG.md

Co-authored-by: Andrew Vivash <andy@fission.codes>
Signed-off-by: Steven Vandevelde <icid.asset@gmail.com>

---------

Signed-off-by: Steven Vandevelde <icid.asset@gmail.com>
Co-authored-by: Andrew Vivash <andy@fission.codes>
  • Loading branch information
icidasset and avivash committed Feb 3, 2023
1 parent 0e32247 commit d0ecd0a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### v0.36.1

Fixes an issue with the CID log, which, in certain scenarios, caused Webnative to load the wrong version of an account's file system.

### v0.36.0

#### Breaking changes
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webnative",
"version": "0.36.0",
"version": "0.36.1",
"description": "Webnative SDK",
"keywords": [
"WebCrypto",
Expand Down
2 changes: 1 addition & 1 deletion src/common/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const VERSION = "0.36.0"
export const VERSION = "0.36.1"
export const WASM_WNFS_VERSION = "0.1.7"
9 changes: 5 additions & 4 deletions src/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function loadFileSystem({ config, dependencies, eventEmitter, rootK

// Determine the correct CID of the file system to load
const dataCid = navigator.onLine ? await getDataRoot(reference, username, { maxRetries: 20 }) : null
const logIdx = dataCid ? cidLog.length() - cidLog.indexOf(dataCid) - 1 : -1
const logIdx = dataCid ? cidLog.indexOf(dataCid) : -1

if (!navigator.onLine) {
// Offline, use local CID
Expand All @@ -59,15 +59,16 @@ export async function loadFileSystem({ config, dependencies, eventEmitter, rootK
if (cid) manners.log("📓 No DNSLink, using local CID:", cid.toString())
else manners.log("📓 Creating a new file system")

} else if (logIdx === 0) {
} else if (logIdx === cidLog.length() - 1) {
// DNS is up to date
cid = dataCid
manners.log("📓 DNSLink is up to date:", cid.toString())

} else if (logIdx > 0) {
} else if (logIdx !== -1 && logIdx < cidLog.length() - 1) {
// DNS is outdated
cid = cidLog.newest()
const idxLog = logIdx === 1 ? "1 newer local entry" : (cidLog.length() - logIdx - 1).toString() + " newer local entries"
const diff = cidLog.length() - 1 - logIdx
const idxLog = diff === 1 ? "1 newer local entry" : diff.toString() + " newer local entries"
manners.log("📓 DNSLink is outdated (" + idxLog + "), using local CID:", cid.toString())

} else {
Expand Down
4 changes: 2 additions & 2 deletions src/repositories/cid-log.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe("cid-log", () => {
const cid = cids[ idx ]

// Get the index of test cid after all CIDs have been added
const index = await cidLog.indexOf(cid)
const index = cidLog.indexOf(cid)

expect(index).toEqual(idx)
})
Expand All @@ -85,7 +85,7 @@ describe("cid-log", () => {
const cid = cids[ cids.length - 1 ]

// Get the newest cid after all CIDs have been added
const newest = await cidLog.newest()
const newest = cidLog.newest()

expect(newest.toString()).toEqual(cid.toString())
})
Expand Down

0 comments on commit d0ecd0a

Please sign in to comment.