mafintosh / mafintosh/append-tree

Possible bug dealing with deletions

Open
#6 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
55
Forks
13
PR merge metrics
No merged PRs in 30d

Description

I'm writing a recursive delete algorithm, which looks like this:

```js
function recurseDelete (archive, targetPath, st) {
return co(function* () {
// fetch stat if needed
if (!st) {
st = yield stat(archive, targetPath)
}
if (st.isFile()) {
// delete file
return new Promise((resolve, reject) => {
console.log('unlink', targetPath)
archive.unlink(targetPath, (err) => {
if (err) reject(toBeakerError(err, 'unlink'))
else resolve()
})
})
} else if (st.isDirectory()) {
// fetch children
var children = yield readdir(archive, targetPath)
// delete children
yield Promise.all(children.map(childName =>
recurseDelete(archive, path.join(targetPath, childName)))
)
// delete self
return new Promise((resolve, reject) => {
console.log('rmdir', targetPath)
archive.rmdir(targetPath, err => {
if (err) reject(toBeakerError(err, 'rmdir'))
else resolve()
})
})
} else {
throw new Error('Unexpectedly encountered an entry which is neither a file or directory at', path)
}
})
}
```

That's being run against the following file-tree:

```
a
b/ (dir)
b/a/ (dir)
b/b
b/c
b/d/ (dir)
b/d/a
b/d/b
b/d/c/ (dir)
b/d/c/a
b/d/d
c/ (dir)
c/b/ (dir)
```

Specifically against the `/b` folder. A working log would look like this:

```
unlink b/b
unlink b/c
rmdir b/a
unlink b/d/d
unlink b/d/a
unlink b/d/b
unlink b/d/c/a
rmdir b/d/c
rmdir b/d
rmdir b
```

But the log I get is this:

```
unlink b/b
unlink b/c
rmdir b/a
unlink b/d/d
unlink b/d/a
unlink b/d/b
unlink b/d/c/a
rmdir b/d/c
Error: File not found
```

For some reason, `rmdir('/b/d/c')` is failing with File not found. If I run the entire method on the '/b/d' folder, no such error occurs!

I'm wondering if the record of the '/b/d/c' folder is getting lost somehow?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the recursive delete algorithm in the issue and reproduce it against the shown tree, specifically deleting /b and comparing the expected and observed logs. Trace the operations around b/d/c and the append-only tree state to determine why rmdir reports File not found. Done means recursive deletion of /b completes without the reported error and preserves the expected operation order.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.