Skip to content
This repository was archived by the owner on Aug 4, 2022. It is now read-only.

Commit ae1d45b

Browse files
authored
Merge pull request #23 from secure-rm/develop
4.2.0
2 parents 3fa3b57 + 7355f47 commit ae1d45b

File tree

11 files changed

+85
-51
lines changed

11 files changed

+85
-51
lines changed

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: [secure-rm, oganexon] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: secure_rm # Replace with a single Patreon username
5+
# open_collective: # Replace with a single Open Collective username
6+
# ko_fi: # Replace with a single Ko-fi username
7+
# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
# liberapay: # Replace with a single Liberapay username
10+
# issuehunt: # Replace with a single IssueHunt username
11+
# otechie: # Replace with a single Otechie username
12+
# custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

.github/workflows/npmpublish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
with:
4040
node-version: 12
4141
registry-url: https://npm.pkg.github.com/
42-
scope: '@your-github-username'
42+
scope: '@secure-rm'
4343
- run: npm ci
4444
- run: npm publish
4545
env:

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414

1515
<!-- ## [Unreleased] -->
1616

17+
## [4.2.0] - 2019-11-02
18+
19+
### Changed
20+
21+
- `secure` standard now also rename folders.
22+
23+
### Fixed
24+
25+
- Unhandled errors.
26+
1727
## [4.1.0] - 2019-10-29
1828

1929
### Changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ srm('./folder/*.js')
6363

6464
[Visit the wiki](https://github.com/secure-rm/core/wiki) to discover all the possibilities secure-rm offers!
6565

66-
- Choose a standard,
67-
- Customize your standard,
68-
- Respond to events,
69-
- etc.
66+
- 📚 [Choose a standard](https://github.com/secure-rm/core/wiki/Standards)
67+
- ⚙️ [Customize your standard](https://github.com/secure-rm/core/wiki/Custom-Standard)
68+
- 📗 [Unlink Methods](https://github.com/secure-rm/core/wiki/Unlink-Methods)
69+
- 📙 [RmDir Methods](https://github.com/secure-rm/core/wiki/RmDir-Methods)
70+
-[Respond to events](https://github.com/secure-rm/core/wiki/Events)
71+
- 🚩 [Troubleshooting - Common issues](https://github.com/secure-rm/core/wiki/Troubleshooting---Common-issues)
7072

7173
### Examples:
7274
```javascript

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "secure-rm",
3-
"version": "4.1.0",
3+
"version": "4.2.0",
44
"description": "Completely erases files by making recovery impossible.",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/rmdir.ts

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@ import { eventEmitter, eventError, tree } from './events'
66

77
type StepFunction = (p: string, uuid: string) => Promise<string>
88

9-
interface FakeLogError {
10-
(message?: string | undefined): Error
11-
code: string
12-
}
13-
149
export default class RmDir {
1510
private steps: Array<StepFunction>
1611
compile: (uuid: string) => typeof fs.rmdir
1712

18-
constructor () {
13+
constructor() {
1914
this.steps = []
2015
this.compile = (uuid) => {
2116
tree[uuid] = []
@@ -27,36 +22,40 @@ export default class RmDir {
2722
}
2823
this.steps.reduce((prev: Promise<string>, next: StepFunction) => {
2924
return prev.then((p) => next(p, uuid))
30-
/* .catch((err: NodeJS.ErrnoException) => {
31-
eventError(err, p as string)
32-
callback!(err)
33-
return Promise.reject(err)
34-
}) */
25+
.catch((err: NodeJS.ErrnoException) => {
26+
if (err.message !== 'handledPromise') {
27+
eventError(err, p as string)
28+
callback!(err)
29+
}
30+
return Promise.reject(new Error('handledPromise'))
31+
})
3532
}, this.init(p as string))
3633
.then(() => callback!(null))
3734
.catch((err: NodeJS.ErrnoException) => {
38-
eventError(err, p as string)
39-
callback!(err)
35+
if (err.message !== 'handledPromise') {
36+
eventError(err, p as string)
37+
callback!(err)
38+
}
4039
})
4140
},
4241
{ __promisify__: util.promisify(fs.rmdir) } // FIXME
4342
)
4443
}
4544
}
4645

47-
private init (p: string): Promise<string> {
46+
private init(p: string): Promise<string> {
4847
return new Promise((resolve) => {
4948
eventEmitter.emit('start', p)
5049
resolve(p)
5150
})
5251
}
5352

54-
then (fun: StepFunction) {
53+
then(fun: StepFunction) {
5554
this.steps.push(fun)
5655
return this
5756
}
5857

59-
log () {
58+
log() {
6059
this.steps.push(
6160
function (p: string, uuid: string) {
6261
return new Promise((resolve, reject) => {
@@ -76,24 +75,34 @@ export default class RmDir {
7675
}
7776

7877
// Rename to random string
79-
rename () {
78+
rename() {
8079
this.steps.push(
8180
function (p: string) {
8281
return new Promise((resolve, reject) => {
83-
const newName = crypto.randomBytes(9).toString('base64').replace(/\//g, '0').replace(/\+/g, 'a')
84-
const newPath = path.join(path.dirname(p), newName)
85-
eventEmitter.emit('verbose', p, `Renaming to ${newName} `)
86-
fs.rename(p, newPath, (err) => {
82+
fs.readdir(p, (err, files) => {
8783
if (err) reject(err)
88-
else resolve(newPath)
84+
if (!files.length) {
85+
// directory appears to be empty
86+
const newName = crypto.randomBytes(9).toString('base64').replace(/\//g, '0').replace(/\+/g, 'a')
87+
const newPath = path.join(path.dirname(p), newName)
88+
eventEmitter.emit('verbose', p, `Renaming to ${newName} `)
89+
fs.rename(p, newPath, (err) => {
90+
if (err) reject(err)
91+
else resolve(newPath)
92+
})
93+
} else {
94+
fs.rmdir(p, (err) => {
95+
reject(err)
96+
})
97+
}
8998
})
9099
})
91100
})
92101
return this
93102
}
94103

95104
// End function: remove the directory
96-
rmdir () {
105+
rmdir() {
97106
this.steps.push(
98107
function (p: string) {
99108
return new Promise((resolve, reject) => {

src/secure-rm.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface Opts {
1818
}
1919

2020
export interface Options extends Opts {
21-
standard?: string
21+
standard?: keyof typeof standards
2222
}
2323

2424
export interface ParsedOptions extends Opts {
@@ -47,8 +47,6 @@ export function remove (path: string, options?: Options | Callback, callback?: C
4747
else return removePromise(path, options as ParsedOptions, uuid)
4848
}
4949

50-
// (module).exports = secureRm
51-
5250
const defaultGlobOpts = {
5351
nosort: true,
5452
silent: true

src/standards.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ Pass 3: Truncating between 25% and 75% of the file.`,
8989
.random()
9090
.rename()
9191
.truncate()
92-
.unlink()/* ,
92+
.unlink(),
9393
rmdirStandard: new RmDir()
9494
.rename()
95-
.rmdir() */
95+
.rmdir()
9696
}),
9797

9898
'GOST_R50739-95': new Standard({

src/unlink.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ interface ForInterface {
1818

1919
type StepFunction = (file: string, fileSize: number, uuid: string) => Promise<FileInfo>
2020

21-
// Function to offset an array
22-
// const offset = (arr: number[], offset: number) => [...arr.slice(offset), ...arr.slice(0, offset)]
23-
2421
export default class Unlink {
2522
private steps: Array<StepFunction>
2623
compile: (token: string) => typeof fs.unlink
@@ -33,16 +30,20 @@ export default class Unlink {
3330
(file: fs.PathLike, callback: (err: NodeJS.ErrnoException | null) => void) => {
3431
this.steps.reduce((prev: Promise<FileInfo>, next: StepFunction) => {
3532
return prev.then(({ file, fileSize }) => next(file, fileSize, uuid))
36-
/* .catch((err: NodeJS.ErrnoException) => {
37-
eventError(err, file as string)
38-
callback(err)
39-
return Promise.reject(err)
40-
}) */
33+
.catch((err: NodeJS.ErrnoException) => {
34+
if (err.message !== 'handledPromise') {
35+
eventError(err, file as string)
36+
callback(err)
37+
}
38+
return Promise.reject(new Error('handledPromise'))
39+
})
4140
}, this.init(file as string))
4241
.then(() => callback(null))
4342
.catch((err: NodeJS.ErrnoException) => {
44-
eventError(err, file as string)
45-
callback(err)
43+
if (err.message !== 'handledPromise') {
44+
eventError(err, file as string)
45+
callback(err)
46+
}
4647
})
4748
},
4849
{ __promisify__: util.promisify(fs.unlink) } // FIXME

0 commit comments

Comments
 (0)