Skip to content

Commit

Permalink
fix: Add rimraf to fix error deleting recursively on Windows Fixes #170
Browse files Browse the repository at this point in the history
  • Loading branch information
OstlerDev committed Aug 31, 2015
1 parent 653694f commit 58d3f22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"url": "https://github.com/OstlerDev/PopcornTV.git"
},
"dependencies": {
"URIjs": "^1.16.0",
"file-type": "^2.7.0",
"git-rev": "^0.2.1",
"iconv-lite": "^0.4.11",
Expand All @@ -25,10 +26,10 @@
"read-chunk": "^1.0.1",
"read-torrent": "^1.3.0",
"request": "2.55.0",
"rimraf": "^2.4.3",
"streamify": "^0.2.4",
"torrent-stream": "^0.21.3",
"underscore": "^1.7.0",
"URIjs": "^1.16.0",
"winston": "^1.0.0",
"winston-loggly": "^1.1.0",
"xml": "^1.0.0",
Expand Down
28 changes: 6 additions & 22 deletions webserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function startWebServer(localIp) {
if (path.extname(fileName) === ".mp4") {
logger.Debug('Deleting ' + fileName);
try{
fs.unlinkSync(fileName);
fs.unlinkSync(__dirname + '/' + fileName);
}catch(e){
logger.warning('Unable to delete file.');
}
Expand Down Expand Up @@ -727,27 +727,11 @@ function startSSLWebServer(localIp) {
logger.Web("SSL Web: listening on " + localIp + ":" + port);
}
var deleteFolderRecursive = function(locpath) {
if( fs.existsSync(locpath) ) {
fs.readdirSync(locpath).forEach(function(file,index){
var curPath = path.join(locpath, file);
if(fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
logger.Debug('Deleting ' + curPath);
try {
fs.unlinkSync(curPath);
} catch(e){
logger.warning('Cannot delete file.'); // Omit sending the file as then it is proof that the user downloaded the file.
}

}
});
try{
fs.rmdirSync(locpath);
} catch (e) {
logger.warning('Unable to delete path.'); // Omit sending path so that it is not logged to server.
}
}
var rimraf = require('rimraf');
rimraf(locpath, function(error){
if (error) logger.error(error);
else logger.notice('Path ' + locpath + ' Removed!');
})
};

var spawn = require('child_process').spawn;
Expand Down

0 comments on commit 58d3f22

Please sign in to comment.