Skip to content

Commit

Permalink
Merge pull request #225 from qgustavor/next
Browse files Browse the repository at this point in the history
Release - v1.3.3
  • Loading branch information
qgustavor authored Oct 16, 2024
2 parents 348efa5 + 2122ccc commit 04fb8fd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/file.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class File extends EventEmitter {
this.key = opt.key ? formatKey(opt.key) : null
this.type = opt.directory ? 1 : 0
this.directory = !!opt.directory
if (this.directory) this.children = []

// Accept an API object
this.api = opt.api || API.getGlobalApi()
Expand Down Expand Up @@ -48,6 +49,7 @@ class File extends EventEmitter {
this.directory = !!opt.t
this.owner = opt.u
this.name = null
if (this.directory) this.children = []

if (!aes || !opt.k) return

Expand Down Expand Up @@ -136,7 +138,6 @@ class File extends EventEmitter {
const parent = filesMap[file.p]
if (parent) {
const fileObj = filesMap[file.h]
if (!parent.children) parent.children = []
parent.children.push(fileObj)
fileObj.parent = parent
}
Expand Down
1 change: 1 addition & 0 deletions lib/mutable-file.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class MutableFile extends File {
this.timestamp = opt.ts
this.type = opt.t
this.directory = !!this.type
if (this.directory) this.children = []

if (opt.k) {
const idKeyPairs = opt.k.split('/')
Expand Down
2 changes: 0 additions & 2 deletions lib/storage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ class Storage extends EventEmitter {
// todo: move to setParent() to avoid duplicate.
oldparent.children.splice(oldparent.children.indexOf(file), 1)
file.parent = this.files[f.p]
if (!file.parent.children) file.parent.children = []
file.parent.children.push(file)
file.emit('move', oldparent)
this.emit('move', file, oldparent)
Expand Down Expand Up @@ -254,7 +253,6 @@ class Storage extends EventEmitter {

// Issue 58: some accounts have orphan files
if (parent) {
if (!parent.children) parent.children = []
parent.children.push(file)
file.parent = parent
}
Expand Down
6 changes: 6 additions & 0 deletions test/storage.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,12 @@ test.serial('Should navigate to files using strings', t => {
t.is(matchingFile.size, 16)
})

test.serial('All directories should have children', t => {
for (const node of Object.values(storage.files)) {
t.is(!!node.directory, !!node.children)
}
})

test.serial('Should logout from MEGA', t => {
return new Promise((resolve, reject) => {
storage.close((error) => {
Expand Down

0 comments on commit 04fb8fd

Please sign in to comment.