Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
Restore destroy() fix for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed May 22, 2019
1 parent c6957d0 commit 53599da
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion leveldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN
const binding = require('./binding')
const ChainedBatch = require('./chained-batch')
const Iterator = require('./iterator')
const fs = require('fs')

function LevelDOWN (location) {
if (!(this instanceof LevelDOWN)) {
Expand Down Expand Up @@ -121,7 +122,28 @@ LevelDOWN.destroy = function (location, callback) {
throw new Error('destroy() requires a callback function argument')
}

binding.destroy_db(location, callback)
binding.destroy_db(location, function (err) {
if (err) return callback(err)

// On Windows, RocksDB silently fails to remove the directory because its
// Logger, which is instantiated on destroy(), has an open file handle on a
// LOG file. Destroy() removes this file but Windows won't actually delete
// it until the handle is released. This happens when destroy() goes out of
// scope, which disposes the Logger. So back in JS-land, we can again
// attempt to remove the directory. This is merely a workaround because
// arguably RocksDB should not instantiate a Logger or open a file at all.
fs.rmdir(location, function (err) {
if (err) {
// Ignore this error in case there are non-RocksDB files left.
if (err.code === 'ENOTEMPTY') return callback()
if (err.code === 'ENOENT') return callback()

return callback(err)
}

callback()
})
})
}

LevelDOWN.repair = function (location, callback) {
Expand Down

0 comments on commit 53599da

Please sign in to comment.