Skip to content

Commit

Permalink
fix: move cache to os.tmpdir() (#562)
Browse files Browse the repository at this point in the history
* fix: move cache to os.tmpdir()

* revert snapshot
  • Loading branch information
ShadyZOZ authored Jun 18, 2020
1 parent 78858bf commit 8f3e54b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bin/anyproxy
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ program

if (program.clear) {
require('../lib/certMgr').clearCerts(() => {
util.deleteFolderContentsRecursive(util.getAnyProxyPath('cache'));
util.deleteFolderContentsRecursive(util.getAnyProxyTmpPath());
console.log(color.green('done !'));
process.exit(0);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const WS_MESSAGE_FILE_PRFIX = 'ws_message_';
const CACHE_DIR_PREFIX = 'cache_r';
function getCacheDir() {
const rand = Math.floor(Math.random() * 1000000),
cachePath = path.join(proxyUtil.getAnyProxyPath('cache'), './' + CACHE_DIR_PREFIX + rand);
cachePath = path.join(proxyUtil.getAnyProxyTmpPath(), './' + CACHE_DIR_PREFIX + rand);

fs.mkdirSync(cachePath);
return cachePath;
Expand Down
2 changes: 1 addition & 1 deletion lib/ruleLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const path = require('path');
const fs = require('fs');
const request = require('request');

const cachePath = proxyUtil.getAnyProxyPath('cache');
const cachePath = proxyUtil.getAnyProxyTmpPath();

/**
* download a file and cache
Expand Down
12 changes: 11 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ const fs = require('fs'),
mime = require('mime-types'),
color = require('colorful'),
child_process = require('child_process'),
os = require('os'),
Buffer = require('buffer').Buffer,
logUtil = require('./log');
const networkInterfaces = require('os').networkInterfaces();

const networkInterfaces = os.networkInterfaces();

// {"Content-Encoding":"gzip"} --> {"content-encoding":"gzip"}
module.exports.lower_keys = (obj) => {
Expand Down Expand Up @@ -52,6 +54,14 @@ module.exports.getAnyProxyPath = function (pathName) {
return targetPath;
}

module.exports.getAnyProxyTmpPath = function () {
const targetPath = path.join(os.tmpdir(), 'anyproxy', 'cache');
if (!fs.existsSync(targetPath)) {
fs.mkdirSync(targetPath, { recursive: true });
}
return targetPath;
}

module.exports.simpleRender = function (str, object, regexp) {
return String(str).replace(regexp || (/\{\{([^{}]+)\}\}/g), (match, name) => {
if (match.charAt(0) === '\\') {
Expand Down

0 comments on commit 8f3e54b

Please sign in to comment.