Skip to content

Commit

Permalink
Remove cache folder recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Nov 19, 2018
1 parent 11ea0e0 commit 0c2f967
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- Alle Abhängigkeiten aktualisiert

### Fixed

- Bilder im Cacheordner werden rekursiv gelöscht, bevor neue Bilder erstellt werden

## [1.0.0-beta.2] - 2018-11-16

### Changed
Expand Down
25 changes: 24 additions & 1 deletion src/imagestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ let createThumbnailFromImage = (imagePath, name) => {
});
};

/**
* Remove folder recursive
* Thanks to https://stackoverflow.com/a/32197381
*/
let deleteFolderRecursive = function(folder) {
if (fs.existsSync(folder)) {
fs.readdirSync(folder).forEach(function(file, index) {
var curPath = folder + path.sep + file;

if (fs.lstatSync(curPath).isDirectory()) {
// recurse
deleteFolderRecursive(curPath);
} else {
// delete file
fs.unlinkSync(curPath);
}
});

fs.rmdirSync(folder);
}
};

// Constructor
function ImageStore() {
basePath = electron.remote.app.getPath('userData') + path.sep + 'imagestore';
Expand All @@ -69,7 +91,8 @@ function ImageStore() {
ImageStore.prototype.reset = function() {
// Reset image folder
try {
fs.rmdirSync(basePath);
deleteFolderRecursive(basePath);
console.log('Image Cache Folder wurde gelöscht');

try {
fs.mkdirSync(basePath);
Expand Down

0 comments on commit 0c2f967

Please sign in to comment.