Skip to content

Commit 8b432b9

Browse files
committed
fixing a bug where max cache files would delete download cache
1 parent 5577600 commit 8b432b9

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

lib/clean.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,21 @@ function cleanup() {
3737
function cleanupCache() {
3838
const cacheLocation = getUserCachePath(this.options);
3939
if (fse.existsSync(cacheLocation)) {
40-
this.serverless.cli.log(`Removing static caches at: ${cacheLocation}`);
40+
if (this.serverless) {
41+
this.serverless.cli.log(`Removing static caches at: ${cacheLocation}`);
42+
}
4143

4244
// Only remove cache folders that we added, just incase someone accidentally puts a weird
4345
// static cache location so we don't remove a bunch of personal stuff
4446
promises = [];
45-
glob.sync([path.join(cacheLocation, '*')], {mark: true, dot: false}).forEach((file) => {
46-
if (file.endsWith('_slspyc/')) {
47-
promises.push( fse.removeAsync(file) );
48-
}
47+
glob.sync([path.join(cacheLocation, '*slspyc/')], {mark: true, dot: false}).forEach((file) => {
48+
promises.push( fse.removeAsync(file) );
4949
});
5050
return BbPromise.all( promises );
5151
} else {
52-
this.serverless.cli.log(`No static cache found`);
52+
if (this.serverless) {
53+
this.serverless.cli.log(`No static cache found`);
54+
}
5355
return BbPromise.resolve();
5456
}
5557
}

lib/pip.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function installRequirements(targetFolder, serverless, options) {
6565

6666
// If we want a download cache...
6767
if (options.useDownloadCache) {
68-
const downloadCacheDir = path.join(getUserCachePath(options), 'downloadCache_slspyc');
68+
const downloadCacheDir = path.join(getUserCachePath(options), 'downloadCacheslspyc');
6969
serverless.cli.log(`Using download cache directory ${downloadCacheDir}`);
7070
fse.ensureDirSync(downloadCacheDir);
7171
pipCmd.push('--cache-dir', downloadCacheDir);
@@ -121,7 +121,7 @@ function installRequirements(targetFolder, serverless, options) {
121121
}
122122
// If we want a download cache...
123123
if (options.useDownloadCache) {
124-
const downloadCacheDir = path.join(getUserCachePath(options), 'downloadCache_slspyc');
124+
const downloadCacheDir = path.join(getUserCachePath(options), 'downloadCacheslspyc');
125125
serverless.cli.log(`Using download cache directory ${downloadCacheDir}`);
126126
fse.ensureDirSync(downloadCacheDir);
127127
// And now push it to a volume mount and to pip...

test.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ teardown() {
7878
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useDownloadCache: true/' serverless.yml
7979
sls package
8080
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
81-
ls $USR_CACHE_DIR/downloadCache_slspyc/http
81+
ls $USR_CACHE_DIR/downloadCacheslspyc/http
8282
}
8383

8484
@test "py3.6 uses download cache with useDownloadCache + cacheLocation option" {
@@ -87,7 +87,7 @@ teardown() {
8787
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
8888
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useDownloadCache: true\n cacheLocation: .requirements-cache/' serverless.yml
8989
sls package
90-
ls .requirements-cache/downloadCache_slspyc/http
90+
ls .requirements-cache/downloadCacheslspyc/http
9191
}
9292

9393
@test "py3.6 uses download cache with dockerizePip + useDownloadCache option" {
@@ -97,7 +97,7 @@ teardown() {
9797
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useDownloadCache: true/' serverless.yml
9898
sls --dockerizePip=true package
9999
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
100-
ls $USR_CACHE_DIR/downloadCache_slspyc/http
100+
ls $USR_CACHE_DIR/downloadCacheslspyc/http
101101
}
102102

103103
@test "py3.6 uses download cache with dockerizePip + useDownloadCache + cacheLocation option" {
@@ -106,7 +106,7 @@ teardown() {
106106
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
107107
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useDownloadCache: true\n cacheLocation: .requirements-cache/' serverless.yml
108108
sls --dockerizePip=true package
109-
ls .requirements-cache/downloadCache_slspyc/http
109+
ls .requirements-cache/downloadCacheslspyc/http
110110
}
111111

112112
@test "py2.7 can package flask with default options" {

0 commit comments

Comments
 (0)