@zowe/cli
Version:
Zowe CLI is a command line interface (CLI) that provides a simple and streamlined way to interact with IBM z/OS.
110 lines • 4 kB
JavaScript
;
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/
Object.defineProperty(exports, "__esModule", { value: true });
const minimatch = require("minimatch");
const imperative_1 = require("@zowe/imperative");
const ZosFiles_messages_1 = require("../constants/ZosFiles.messages");
const pathUtils = require("path");
var TransferMode;
(function (TransferMode) {
TransferMode[TransferMode["BINARY"] = 0] = "BINARY";
TransferMode[TransferMode["TEXT"] = 1] = "TEXT";
})(TransferMode = exports.TransferMode || (exports.TransferMode = {}));
/**
* Attributes for a set of files relating to how they will be uploaded to USS
*/
class ZosFilesAttributes {
constructor(attributesFileContents, basePath) {
this.attributes = new Map();
this.parse(attributesFileContents);
this.basePath = basePath;
}
fileShouldBeUploaded(path) {
let result = false;
const attributes = this.findLastMatchingAttributes(path);
if (attributes === null) {
result = true;
}
else {
result = !attributes.ignore;
}
imperative_1.Logger.getAppLogger().debug("path: " + path + " : " + attributes + " result = " + result);
return result;
}
getFileTransferMode(path) {
const attributes = this.findLastMatchingAttributes(path);
if (attributes === null) {
return TransferMode.BINARY;
}
if (attributes.localEncoding === attributes.remoteEncoding) {
return TransferMode.BINARY;
}
else {
return TransferMode.TEXT;
}
}
getRemoteEncoding(path) {
const attributes = this.findLastMatchingAttributes(path);
if (attributes === null) {
return "ISO8859-1";
}
return attributes.remoteEncoding;
}
getLocalEncoding(path) {
const attributes = this.findLastMatchingAttributes(path);
if (attributes === null) {
return "ISO8859-1";
}
return attributes.localEncoding;
}
parse(attributesFileContents) {
const lines = attributesFileContents.split("\n");
let lineNumber = 0;
lines.forEach((line) => {
lineNumber++;
line = line.trim();
if (line === "" || line.startsWith("#")) {
return;
}
const parts = line.trim().split(/\s+/);
const pattern = parts[0];
const localEncoding = parts[1];
const remoteEncoding = parts[2];
if (parts.length > ZosFilesAttributes.MAX_EXPECTED_FIELDS || parts.length < ZosFilesAttributes.MIN_EXPECTED_FIELDS) {
throw new Error(imperative_1.TextUtils.formatMessage(ZosFiles_messages_1.ZosFilesMessages.invalidAttributesSyntax.message, { lineNumber }));
}
if (localEncoding === "-") {
this.attributes.set(pattern, { ignore: true });
}
else {
this.attributes.set(pattern, { ignore: false, localEncoding, remoteEncoding });
}
});
}
findLastMatchingAttributes(path) {
let relativePath = path;
if (this.basePath) {
relativePath = pathUtils.relative(this.basePath, path);
}
let result = null;
this.attributes.forEach((attributes, pattern) => {
if (minimatch(relativePath, pattern, { matchBase: true, dot: true })) {
result = attributes;
}
});
return result;
}
}
exports.ZosFilesAttributes = ZosFilesAttributes;
ZosFilesAttributes.MAX_EXPECTED_FIELDS = 3;
ZosFilesAttributes.MIN_EXPECTED_FIELDS = 2;
//# sourceMappingURL=ZosFilesAttributes.js.map