lib/archivist/vaults/file/directories.js
function purgeEmptyParentFolders(rootPath, subfolderPath, logger, cb) {
	var fullPath = path.join(rootPath, subfolderPath);

	// Don't delete if we have reached the base
	if (!subfolderPath || subfolderPath === '.') {
		return cb();
	}

	fs.rmdir(fullPath, function (error) {
		if (error) {
			return cb(error);
		}

		logger.verbose('Purged empty subfolder:', fullPath);

		return purgeEmptyParentFolders(rootPath, path.dirname(subfolderPath), logger, cb);
	});
}
function purgeEmptyParentFolders(rootPath, subfolderPath, logger, cb) {
	var fullPath = path.join(rootPath, subfolderPath);

	// Don't delete if we have reached the base
	if (!subfolderPath || subfolderPath === '.') {
		return cb();
	}

	fs.rmdir(fullPath, function (error) {
		if (error) {
			return cb(error);
		}

		logger.verbose('Purged empty subfolder:', fullPath);

		return purgeEmptyParentFolders(rootPath, path.dirname(subfolderPath), logger, cb);
	});
}
function purgeEmptyParentFolders ( rootPath , subfolderPath , logger , cb ) { var fullPath = path . join ( rootPath , subfolderPath ) ; // Don't delete if we have reached the base if ( ! subfolderPath || subfolderPath === '.' ) { return cb ( ) ; } fs . rmdir ( fullPath , function ( error ) { if ( error ) { return cb ( error ) ; } logger . verbose ( 'Purged empty subfolder:' , fullPath ) ; return purgeEmptyParentFolders ( rootPath , path . dirname ( subfolderPath ) , logger , cb ) ; } ) ; }
Recursively purges empty folders from subfolderPath and working its way through its parents until
reaching rootPath.

@param {String} rootPath - root path to which the given subfolder belongs
@param {String} subfolderPath - subfolder path relative to the root path
@param {Object} logger
@param {Function} cb
Recursively purges empty folders from subfolderPath and working its way through its parents until reaching rootPath .