Skip to content

Commit 3a9d934

Browse files
committed
Fixed removing of empty directories in the bundled mode.
1 parent 904389e commit 3a9d934

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

bundles.js

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ exports.make = function(callback) {
106106
p = p.replace(REGAPPENDREPLACE, '/');
107107
}
108108

109-
var exists = false;
109+
var exists = null;
110110
try {
111-
exists = Fs.statSync(Path.join(target, p)) != null;
111+
exists = Fs.statSync(Path.join(target, p));
112112
} catch (e) {}
113113

114114
if ((dirname === pathupdate || dirname === pathstartup) && !exists) {
@@ -244,7 +244,6 @@ function normalize(path) {
244244
function cleanFiles(callback) {
245245

246246
var path = PATH.root(CONF.directory_src);
247-
var length = path.length - 1;
248247
var blacklist = {};
249248

250249
blacklist[CONF.directory_public] = 1;
@@ -268,7 +267,7 @@ function cleanFiles(callback) {
268267
}
269268

270269
if (meta.files && meta.files.length) {
271-
for (var i = 0, length = meta.files.length; i < length; i++) {
270+
for (var i = 0; i < meta.files.length; i++) {
272271
var filename = meta.files[i];
273272
var dir = filename.substring(0, filename.indexOf('/', 1) + 1);
274273
if (!blacklist[dir]) {
@@ -280,11 +279,33 @@ function cleanFiles(callback) {
280279
}
281280

282281
if (meta.directories && meta.directories.length) {
283-
meta.directories.quicksort('length');
284-
for (var i = 0, length = meta.directories.length; i < length; i++) {
282+
meta.directories.quicksort('length_desc');
283+
for (var i = 0; i < meta.directories.length; i++) {
285284
try {
286-
if (!blacklist[meta.directories[i]])
287-
Fs.rmdirSync(Path.join(path, meta.directories[i]));
285+
286+
var p = Path.join(path, meta.directories[i]);
287+
288+
if (blacklist[meta.directories[i]])
289+
continue;
290+
291+
while (true) {
292+
293+
var files = Fs.readdirSync(p);
294+
if (files.length)
295+
break;
296+
297+
try {
298+
Fs.rmdirSync(p);
299+
} catch (e) {
300+
break;
301+
}
302+
303+
p = Path.join(path, '..');
304+
305+
if (p.length < path || p === path)
306+
break;
307+
}
308+
288309
} catch (e) {}
289310
}
290311
}
@@ -320,14 +341,19 @@ function copyFiles(files, callback) {
320341
return next();
321342

322343
var filename = Path.join(path, file.name);
323-
var exists = false;
324344
var ext = U.getExtension(file.name);
325345
var append = file.type === 3;
346+
var exists = null;
326347

327348
try {
328-
exists = Fs.statSync(filename) != null;
349+
exists = Fs.statSync(filename);
329350
} catch (e) {}
330351

352+
if (exists && (!exists.isFile() | exists.isSocket())) {
353+
next();
354+
return;
355+
}
356+
331357
// DB file
332358
if (file.type === 1 && exists) {
333359
next();

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- fixed linking `CONF.node_modules` path to the `F.require()` method
2222
- fixed `.nocache()` in the release mode
2323
- fixed loading apps if the plugin's `index.js` doesn't exist
24+
- fixed removing of empty directories in the bundled mode
2425

2526
========================
2627
0.0.58

0 commit comments

Comments
 (0)