src/extensions/default/AutoUpdate/node/AutoUpdateDomain.js
function performCleanup(requester, filesToCache, notifyBack) {
        var currentRequester = requester || "";
        function filterFilesAndNotify(files, filesToCacheArr, notifyBackToBrackets) {
            files.forEach(function (file) {
                var fileExt = path.extname(path.basename(file));
                if (filesToCacheArr.indexOf(fileExt) < 0) {
                    var fileFullPath = updateDir + '/' + file;
                    try {
                        fs.removeSync(fileFullPath);
                    } catch (e) {
                        console.log("AutoUpdate : Exception occured in removing ", fileFullPath, e);
                    }
                }
            });
            if (notifyBackToBrackets) {
                postMessageToBrackets(MessageIds.NOTIFY_SAFE_TO_DOWNLOAD, currentRequester);
            }
        }

        fs.stat(updateDir)
            .then(function (stats) {
                if (stats) {
                    if (filesToCache) {
                        fs.readdir(updateDir)
                            .then(function (files) {
                                filterFilesAndNotify(files, filesToCache, notifyBack);
                            })
                            .catch(function (err) {
                                console.log("AutoUpdate : Error in Reading Update Dir for Cleanup : " + err.toString());
                                postMessageToBrackets(MessageIds.SHOW_ERROR_MESSAGE,
                                                      currentRequester, nodeErrorMessages.UPDATEDIR_READ_FAILED);
                            });
                    } else {
                        fs.remove(updateDir)
                            .then(function () {
                                console.log('AutoUpdate : Update Directory in AppData Cleaned: Complete');
                            })
                            .catch(function (err) {
                                console.log("AutoUpdate : Error in Cleaning Update Dir : " + err.toString());
                                postMessageToBrackets(MessageIds.SHOW_ERROR_MESSAGE,
                                                      currentRequester, nodeErrorMessages.UPDATEDIR_CLEAN_FAILED);
                            });
                    }
                }
            })
            .catch(function (err) {
                console.log("AutoUpdate : Error in Reading Update Dir stats for Cleanup : " + err.toString());
                postMessageToBrackets(MessageIds.SHOW_ERROR_MESSAGE,
                                      currentRequester, nodeErrorMessages.UPDATEDIR_CLEAN_FAILED);
            });
    }
function performCleanup(requester, filesToCache, notifyBack) {
        var currentRequester = requester || "";
        function filterFilesAndNotify(files, filesToCacheArr, notifyBackToBrackets) {
            files.forEach(function (file) {
                var fileExt = path.extname(path.basename(file));
                if (filesToCacheArr.indexOf(fileExt) < 0) {
                    var fileFullPath = updateDir + '/' + file;
                    try {
                        fs.removeSync(fileFullPath);
                    } catch (e) {
                        console.log("AutoUpdate : Exception occured in removing ", fileFullPath, e);
                    }
                }
            });
            if (notifyBackToBrackets) {
                postMessageToBrackets(MessageIds.NOTIFY_SAFE_TO_DOWNLOAD, currentRequester);
            }
        }

        fs.stat(updateDir)
            .then(function (stats) {
                if (stats) {
                    if (filesToCache) {
                        fs.readdir(updateDir)
                            .then(function (files) {
                                filterFilesAndNotify(files, filesToCache, notifyBack);
                            })
                            .catch(function (err) {
                                console.log("AutoUpdate : Error in Reading Update Dir for Cleanup : " + err.toString());
                                postMessageToBrackets(MessageIds.SHOW_ERROR_MESSAGE,
                                                      currentRequester, nodeErrorMessages.UPDATEDIR_READ_FAILED);
                            });
                    } else {
                        fs.remove(updateDir)
                            .then(function () {
                                console.log('AutoUpdate : Update Directory in AppData Cleaned: Complete');
                            })
                            .catch(function (err) {
                                console.log("AutoUpdate : Error in Cleaning Update Dir : " + err.toString());
                                postMessageToBrackets(MessageIds.SHOW_ERROR_MESSAGE,
                                                      currentRequester, nodeErrorMessages.UPDATEDIR_CLEAN_FAILED);
                            });
                    }
                }
            })
            .catch(function (err) {
                console.log("AutoUpdate : Error in Reading Update Dir stats for Cleanup : " + err.toString());
                postMessageToBrackets(MessageIds.SHOW_ERROR_MESSAGE,
                                      currentRequester, nodeErrorMessages.UPDATEDIR_CLEAN_FAILED);
            });
    }
function performCleanup ( requester , filesToCache , notifyBack ) { var currentRequester = requester || "" ; function filterFilesAndNotify ( files , filesToCacheArr , notifyBackToBrackets ) { files . forEach ( function ( file ) { var fileExt = path . extname ( path . basename ( file ) ) ; if ( filesToCacheArr . indexOf ( fileExt ) < 0 ) { var fileFullPath = updateDir + '/' + file ; try { fs . removeSync ( fileFullPath ) ; } catch ( e ) { console . log ( "AutoUpdate : Exception occured in removing " , fileFullPath , e ) ; } } } ) ; if ( notifyBackToBrackets ) { postMessageToBrackets ( MessageIds . NOTIFY_SAFE_TO_DOWNLOAD , currentRequester ) ; } } fs . stat ( updateDir ) . then ( function ( stats ) { if ( stats ) { if ( filesToCache ) { fs . readdir ( updateDir ) . then ( function ( files ) { filterFilesAndNotify ( files , filesToCache , notifyBack ) ; } ) . catch ( function ( err ) { console . log ( "AutoUpdate : Error in Reading Update Dir for Cleanup : " + err . toString ( ) ) ; postMessageToBrackets ( MessageIds . SHOW_ERROR_MESSAGE , currentRequester , nodeErrorMessages . UPDATEDIR_READ_FAILED ) ; } ) ; } else { fs . remove ( updateDir ) . then ( function ( ) { console . log ( 'AutoUpdate : Update Directory in AppData Cleaned: Complete' ) ; } ) . catch ( function ( err ) { console . log ( "AutoUpdate : Error in Cleaning Update Dir : " + err . toString ( ) ) ; postMessageToBrackets ( MessageIds . SHOW_ERROR_MESSAGE , currentRequester , nodeErrorMessages . UPDATEDIR_CLEAN_FAILED ) ; } ) ; } } } ) . catch ( function ( err ) { console . log ( "AutoUpdate : Error in Reading Update Dir stats for Cleanup : " + err . toString ( ) ) ; postMessageToBrackets ( MessageIds . SHOW_ERROR_MESSAGE , currentRequester , nodeErrorMessages . UPDATEDIR_CLEAN_FAILED ) ; } ) ; }
Performs clean up for the contents in Update Directory in AppData
@param {Array} filesToCache - array of file types to cache
@param {boolean} notifyBack  - true if Brackets needs to be
notified post cleanup, false otherwise
Performs clean up for the contents in Update Directory in AppData