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

Commit

Permalink
Merge pull request #23 from secure-rm/develop
Browse files Browse the repository at this point in the history
4.2.0
  • Loading branch information
SteelAlloy committed Nov 2, 2019
2 parents 3fa3b57 + 7355f47 commit ae1d45b
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 51 deletions.
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: [secure-rm, oganexon] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: secure_rm # Replace with a single Patreon username
# open_collective: # Replace with a single Open Collective username
# ko_fi: # Replace with a single Ko-fi username
# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
# liberapay: # Replace with a single Liberapay username
# issuehunt: # Replace with a single IssueHunt username
# otechie: # Replace with a single Otechie username
# custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
2 changes: 1 addition & 1 deletion .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
with:
node-version: 12
registry-url: https://npm.pkg.github.com/
scope: '@your-github-username'
scope: '@secure-rm'
- run: npm ci
- run: npm publish
env:
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

## [4.2.0] - 2019-11-02

### Changed

- `secure` standard now also rename folders.

### Fixed

- Unhandled errors.

## [4.1.0] - 2019-10-29

### Changed
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ srm('./folder/*.js')

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

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

### Examples:
```javascript
Expand Down
14 changes: 7 additions & 7 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": "secure-rm",
"version": "4.1.0",
"version": "4.2.0",
"description": "Completely erases files by making recovery impossible.",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
55 changes: 32 additions & 23 deletions src/rmdir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ import { eventEmitter, eventError, tree } from './events'

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

interface FakeLogError {
(message?: string | undefined): Error
code: string
}

export default class RmDir {
private steps: Array<StepFunction>
compile: (uuid: string) => typeof fs.rmdir

constructor () {
constructor() {
this.steps = []
this.compile = (uuid) => {
tree[uuid] = []
Expand All @@ -27,36 +22,40 @@ export default class RmDir {
}
this.steps.reduce((prev: Promise<string>, next: StepFunction) => {
return prev.then((p) => next(p, uuid))
/* .catch((err: NodeJS.ErrnoException) => {
eventError(err, p as string)
callback!(err)
return Promise.reject(err)
}) */
.catch((err: NodeJS.ErrnoException) => {
if (err.message !== 'handledPromise') {
eventError(err, p as string)
callback!(err)
}
return Promise.reject(new Error('handledPromise'))
})
}, this.init(p as string))
.then(() => callback!(null))
.catch((err: NodeJS.ErrnoException) => {
eventError(err, p as string)
callback!(err)
if (err.message !== 'handledPromise') {
eventError(err, p as string)
callback!(err)
}
})
},
{ __promisify__: util.promisify(fs.rmdir) } // FIXME
)
}
}

private init (p: string): Promise<string> {
private init(p: string): Promise<string> {
return new Promise((resolve) => {
eventEmitter.emit('start', p)
resolve(p)
})
}

then (fun: StepFunction) {
then(fun: StepFunction) {
this.steps.push(fun)
return this
}

log () {
log() {
this.steps.push(
function (p: string, uuid: string) {
return new Promise((resolve, reject) => {
Expand All @@ -76,24 +75,34 @@ export default class RmDir {
}

// Rename to random string
rename () {
rename() {
this.steps.push(
function (p: string) {
return new Promise((resolve, reject) => {
const newName = crypto.randomBytes(9).toString('base64').replace(/\//g, '0').replace(/\+/g, 'a')
const newPath = path.join(path.dirname(p), newName)
eventEmitter.emit('verbose', p, `Renaming to ${newName} `)
fs.rename(p, newPath, (err) => {
fs.readdir(p, (err, files) => {
if (err) reject(err)
else resolve(newPath)
if (!files.length) {
// directory appears to be empty
const newName = crypto.randomBytes(9).toString('base64').replace(/\//g, '0').replace(/\+/g, 'a')
const newPath = path.join(path.dirname(p), newName)
eventEmitter.emit('verbose', p, `Renaming to ${newName} `)
fs.rename(p, newPath, (err) => {
if (err) reject(err)
else resolve(newPath)
})
} else {
fs.rmdir(p, (err) => {
reject(err)
})
}
})
})
})
return this
}

// End function: remove the directory
rmdir () {
rmdir() {
this.steps.push(
function (p: string) {
return new Promise((resolve, reject) => {
Expand Down
4 changes: 1 addition & 3 deletions src/secure-rm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface Opts {
}

export interface Options extends Opts {
standard?: string
standard?: keyof typeof standards
}

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

// (module).exports = secureRm

const defaultGlobOpts = {
nosort: true,
silent: true
Expand Down
4 changes: 2 additions & 2 deletions src/standards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ Pass 3: Truncating between 25% and 75% of the file.`,
.random()
.rename()
.truncate()
.unlink()/* ,
.unlink(),
rmdirStandard: new RmDir()
.rename()
.rmdir() */
.rmdir()
}),

'GOST_R50739-95': new Standard({
Expand Down
21 changes: 11 additions & 10 deletions src/unlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ interface ForInterface {

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

// Function to offset an array
// const offset = (arr: number[], offset: number) => [...arr.slice(offset), ...arr.slice(0, offset)]

export default class Unlink {
private steps: Array<StepFunction>
compile: (token: string) => typeof fs.unlink
Expand All @@ -33,16 +30,20 @@ export default class Unlink {
(file: fs.PathLike, callback: (err: NodeJS.ErrnoException | null) => void) => {
this.steps.reduce((prev: Promise<FileInfo>, next: StepFunction) => {
return prev.then(({ file, fileSize }) => next(file, fileSize, uuid))
/* .catch((err: NodeJS.ErrnoException) => {
eventError(err, file as string)
callback(err)
return Promise.reject(err)
}) */
.catch((err: NodeJS.ErrnoException) => {
if (err.message !== 'handledPromise') {
eventError(err, file as string)
callback(err)
}
return Promise.reject(new Error('handledPromise'))
})
}, this.init(file as string))
.then(() => callback(null))
.catch((err: NodeJS.ErrnoException) => {
eventError(err, file as string)
callback(err)
if (err.message !== 'handledPromise') {
eventError(err, file as string)
callback(err)
}
})
},
{ __promisify__: util.promisify(fs.unlink) } // FIXME
Expand Down
2 changes: 2 additions & 0 deletions test/secure-rm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const srm = require('..')

const { tools } = require('./tools.js')(__dirname, __filename)

test.todo('Predictable errors')

describe('Invalid IDs throw:', () => {
const values = [-1, '1', 10e5, 'string', 'SECURE', ['secure']]
for (let i = 0; i < values.length; i++) {
Expand Down

0 comments on commit ae1d45b

Please sign in to comment.