@@ -3,6 +3,7 @@ const AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN
33const binding = require ( './binding' )
44const ChainedBatch = require ( './chained-batch' )
55const Iterator = require ( './iterator' )
6+ const fs = require ( 'fs' )
67
78function LevelDOWN ( location ) {
89 if ( ! ( this instanceof LevelDOWN ) ) {
@@ -121,7 +122,28 @@ LevelDOWN.destroy = function (location, callback) {
121122 throw new Error ( 'destroy() requires a callback function argument' )
122123 }
123124
124- binding . destroy_db ( location , callback )
125+ binding . destroy_db ( location , function ( err ) {
126+ if ( err ) return callback ( err )
127+
128+ // On Windows, RocksDB silently fails to remove the directory because its
129+ // Logger, which is instantiated on destroy(), has an open file handle on a
130+ // LOG file. Destroy() removes this file but Windows won't actually delete
131+ // it until the handle is released. This happens when destroy() goes out of
132+ // scope, which disposes the Logger. So back in JS-land, we can again
133+ // attempt to remove the directory. This is merely a workaround because
134+ // arguably RocksDB should not instantiate a Logger or open a file at all.
135+ fs . rmdir ( location , function ( err ) {
136+ if ( err ) {
137+ // Ignore this error in case there are non-RocksDB files left.
138+ if ( err . code === 'ENOTEMPTY' ) return callback ( )
139+ if ( err . code === 'ENOENT' ) return callback ( )
140+
141+ return callback ( err )
142+ }
143+
144+ callback ( )
145+ } )
146+ } )
125147}
126148
127149LevelDOWN . repair = function ( location , callback ) {
0 commit comments