Skip to content

Commit

Permalink
switch to filenamify
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed May 28, 2021
1 parent 77cb9d2 commit 21e6ee4
Show file tree
Hide file tree
Showing 5 changed files with 358 additions and 26 deletions.
166 changes: 159 additions & 7 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ function toCommandValue(input) {
exports.toCommandValue = toCommandValue;
//# sourceMappingURL=utils.js.map

/***/ }),

/***/ 83:
/***/ (function(module, __unusedexports, __webpack_require__) {

"use strict";

const filenamify = __webpack_require__(356);
const filenamifyPath = __webpack_require__(244);

const filenamifyCombined = filenamify;
filenamifyCombined.path = filenamifyPath;

module.exports = filenamify;


/***/ }),

/***/ 87:
Expand Down Expand Up @@ -117,6 +133,25 @@ exports.issueCommand = issueCommand;

module.exports = require("child_process");

/***/ }),

/***/ 138:
/***/ (function(module) {

"use strict";


var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;

module.exports = function (str) {
if (typeof str !== 'string') {
throw new TypeError('Expected a string');
}

return str.replace(matchOperatorsRe, '\\$&');
};


/***/ }),

/***/ 211:
Expand Down Expand Up @@ -151,6 +186,72 @@ var Events;
exports.RefKey = "GITHUB_REF";


/***/ }),

/***/ 244:
/***/ (function(module, __unusedexports, __webpack_require__) {

"use strict";

const path = __webpack_require__(622);
const filenamify = __webpack_require__(356);

const filenamifyPath = (filePath, options) => {
filePath = path.resolve(filePath);
return path.join(path.dirname(filePath), filenamify(path.basename(filePath), options));
};

module.exports = filenamifyPath;


/***/ }),

/***/ 356:
/***/ (function(module, __unusedexports, __webpack_require__) {

"use strict";

const trimRepeated = __webpack_require__(567);
const filenameReservedRegex = __webpack_require__(634);
const stripOuter = __webpack_require__(448);

// Doesn't make sense to have longer filenames
const MAX_FILENAME_LENGTH = 100;

const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g; // eslint-disable-line no-control-regex
const reRelativePath = /^\.+/;
const reTrailingPeriods = /\.+$/;

const filenamify = (string, options = {}) => {
if (typeof string !== 'string') {
throw new TypeError('Expected a string');
}

const replacement = options.replacement === undefined ? '!' : options.replacement;

if (filenameReservedRegex().test(replacement) && reControlChars.test(replacement)) {
throw new Error('Replacement string cannot contain reserved filename characters');
}

string = string.replace(filenameReservedRegex(), replacement);
string = string.replace(reControlChars, replacement);
string = string.replace(reRelativePath, replacement);
string = string.replace(reTrailingPeriods, '');

if (replacement.length > 0) {
string = trimRepeated(string, replacement);
string = string.length > 1 ? stripOuter(string, replacement) : string;
}

string = filenameReservedRegex.windowsNames().test(string) ? string + replacement : string;
string = string.slice(0, typeof options.maxLength === 'number' ? options.maxLength : MAX_FILENAME_LENGTH);

return string;
};

module.exports = filenamify;


/***/ }),

/***/ 431:
Expand Down Expand Up @@ -331,6 +432,25 @@ function getInputAsInt(name, options) {
exports.getInputAsInt = getInputAsInt;


/***/ }),

/***/ 448:
/***/ (function(module, __unusedexports, __webpack_require__) {

"use strict";

var escapeStringRegexp = __webpack_require__(138);

module.exports = function (str, sub) {
if (typeof str !== 'string' || typeof sub !== 'string') {
throw new TypeError();
}

sub = escapeStringRegexp(sub);
return str.replace(new RegExp('^' + sub + '|' + sub + '$', 'g'), '');
};


/***/ }),

/***/ 470:
Expand Down Expand Up @@ -576,13 +696,44 @@ function getState(name) {
exports.getState = getState;
//# sourceMappingURL=core.js.map

/***/ }),

/***/ 567:
/***/ (function(module, __unusedexports, __webpack_require__) {

"use strict";

var escapeStringRegexp = __webpack_require__(138);

module.exports = function (str, target) {
if (typeof str !== 'string' || typeof target !== 'string') {
throw new TypeError('Expected a string');
}

return str.replace(new RegExp('(?:' + escapeStringRegexp(target) + '){2,}', 'g'), target);
};


/***/ }),

/***/ 622:
/***/ (function(module) {

module.exports = require("path");

/***/ }),

/***/ 634:
/***/ (function(module) {

"use strict";

/* eslint-disable no-control-regex */
// TODO: remove parens when Node.js 6 is targeted. Node.js 4 barfs at it.
module.exports = () => (/[<>:"\/\\|?*\x00-\x1F]/g);
module.exports.windowsNames = () => (/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i);


/***/ }),

/***/ 669:
Expand All @@ -606,17 +757,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.saveCache = exports.restoreCache = exports.ValidationError = exports.ReserveCacheError = void 0;
const child_process_1 = __webpack_require__(129);
const filenamify_1 = __importDefault(__webpack_require__(83));
const fs_1 = __webpack_require__(747);
const path_1 = __webpack_require__(622);
const util_1 = __webpack_require__(669);
const execAsync = util_1.promisify(child_process_1.exec);
const readDirAsync = util_1.promisify(fs_1.readdir);
function generateCacheName(path) {
return path.replace(/[^a-z0-9]/gi, "_");
}
class ReserveCacheError extends Error {
constructor(message) {
super(message);
Expand All @@ -639,8 +791,8 @@ function checkPaths(paths) {
}
}
function checkKey(key) {
if (key.length > 512) {
throw new ValidationError(`Key Validation Error: ${key} cannot be larger than 512 characters.`);
if (key.length > 255) {
throw new ValidationError(`Key Validation Error: ${key} cannot be larger than 255 characters.`);
}
const regex = /^[^,]*$/;
if (!regex.test(key)) {
Expand Down Expand Up @@ -695,7 +847,7 @@ function restoreCache(paths, primaryKey, restoreKeys, options) {
// @todo order files by name/date
yield streamOutputUntilResolved(mkdirPromise);
const cacheFiles = yield readDirAsync(cacheDir);
const potentialCaches = (restoreKeys || [primaryKey]).map(generateCacheName);
const potentialCaches = (restoreKeys || [primaryKey]).map(key => filenamify_1.default(key));
console.log({ cacheFiles, potentialCaches });
const result = locateCache(potentialCaches, cacheFiles);
if (typeof result !== "object") {
Expand Down Expand Up @@ -733,7 +885,7 @@ function saveCache(paths, key, options) {
checkKey(key);
console.log(JSON.stringify({ env: process.env, paths, key, options }, null, 2));
const cacheDir = path_1.join(`/media/cache/`, process.env.GITHUB_REPOSITORY || "");
const cacheName = `${generateCacheName(key)}.tar.lz4`;
const cacheName = `${filenamify_1.default(key)}.tar.lz4`;
const cachePath = path_1.join(cacheDir, cacheName);
const cmd = `mkdir -p ${cacheDir} && tar cf - ${paths.join(" ")} | lz4 -v > ${cachePath}`;
console.log({ cacheDir, cacheName, cachePath, cmd });
Expand Down
Loading

0 comments on commit 21e6ee4

Please sign in to comment.