* Clean up static cache, remove all items in there * @return {Promise}
()
| 70 | * @return {Promise} |
| 71 | */ |
| 72 | async function cleanupCache() { |
| 73 | const cacheLocation = getUserCachePath(this.options) |
| 74 | if (fse.existsSync(cacheLocation)) { |
| 75 | let cleanupProgress |
| 76 | if (this.serverless) { |
| 77 | if (this.log) { |
| 78 | cleanupProgress = this.progress.get('python-cleanup-cache') |
| 79 | cleanupProgress.notice('Removing static caches') |
| 80 | this.log.info(`Removing static caches at: ${cacheLocation}`) |
| 81 | } else { |
| 82 | this.serverless.cli.log(`Removing static caches at: ${cacheLocation}`) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | // Only remove cache folders that we added, just incase someone accidentally puts a weird |
| 87 | // static cache location so we don't remove a bunch of personal stuff |
| 88 | const files = globSync([path.join(cacheLocation, '*slspyc/')], { |
| 89 | mark: true, |
| 90 | dot: false, |
| 91 | }) |
| 92 | try { |
| 93 | await Promise.all(files.map((file) => fse.remove(file))) |
| 94 | } finally { |
| 95 | cleanupProgress && cleanupProgress.remove() |
| 96 | } |
| 97 | } else { |
| 98 | if (this.serverless) { |
| 99 | if (this.log) { |
| 100 | this.log.info(`No static cache found`) |
| 101 | } else { |
| 102 | this.serverless.cli.log(`No static cache found`) |
| 103 | } |
| 104 | } |
| 105 | return |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | export { cleanup, cleanupCache } |