Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
can also use SFTP chmod for directories now
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Jun 16, 2017
1 parent 49081cf commit 55902c3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 26 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Change Log (vs-deploy)

## 9.26.0 (June 16th, 2017; SFTP)
## 9.26.1 (June 16th, 2017; SFTP)

* added `updateModesOfDirectories` setting for [sftp targets](https://github.com/mkloubert/vs-deploy/wiki/target_sftp), which indicates if a value in `modes` property should also be applied to the directory of a file or not
* bugfixes in [sftp target](https://github.com/mkloubert/vs-deploy/wiki/target_sftp) when setting [file mode](https://github.com/mkloubert/vs-deploy/wiki/target_sftp#modes-for-specific-files) after a file has been uploaded

## 9.25.0 (June 12th, 2017; russian translation)
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vs-deploy",
"displayName": "Deploy",
"description": "Commands for deploying files of your workspace to a destination.",
"version": "9.26.0",
"version": "9.26.1",
"publisher": "mkloubert",
"engines": {
"vscode": "^1.6.0"
Expand Down Expand Up @@ -24453,6 +24453,11 @@
"description": "Prompt for a password if not defined.",
"default": true
},
"updateModesOfDirectories": {
"type": "boolean",
"description": "Also execute 'chmod' for the directory of a file.",
"default": false
},
"description": {
"type": "string",
"description": "A description for the target."
Expand Down
79 changes: 55 additions & 24 deletions src/plugins/sftp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ interface DeployTargetSFTP extends deploy_contracts.TransformableDeployTarget, d
uploaded?: SSHCommands;
connected?: SSHCommands;
closing?: SSHCommands;
updateModesOfDirectories?: boolean;
}

interface FileToUpload {
Expand Down Expand Up @@ -516,36 +517,45 @@ class SFtpPlugin extends deploy_objects.DeployPluginWithContextBase<SFTPContext>
let targetFile = toSFTPPath(Path.join(dir, relativeFilePath));
let targetDirectory = toSFTPPath(Path.dirname(targetFile));

let putOpts: any = {};
if (!deploy_helpers.isNullOrUndefined(target.modes)) {
let getModeValue = (pathVal: string) => {
let mode: number;

let asOctalNumber = (val: any): number => {
if (deploy_helpers.isNullUndefinedOrEmptyString(val)) {
return;
}
if (!deploy_helpers.isNullOrUndefined(target.modes)) {
let asOctalNumber = (val: any): number => {
if (deploy_helpers.isNullUndefinedOrEmptyString(val)) {
return;
}

return parseInt(deploy_helpers.toStringSafe(val).trim(),
8);
};

if ('object' === typeof target.modes) {
for (let p in target.modes) {
let r = new RegExp(p);
return parseInt(deploy_helpers.toStringSafe(val).trim(),
8);
};
if ('object' === typeof target.modes) {
for (let p in target.modes) {
let r = new RegExp(p);

if (r.test(targetFile)) {
mode = asOctalNumber(target.modes[p]);
if (r.test(deploy_helpers.toStringSafe(pathVal))) {
mode = asOctalNumber(target.modes[p]);
}
}
}
}
else {
// handle as string or number
mode = asOctalNumber(target.modes);
else {
// handle as string or number
mode = asOctalNumber(target.modes);
}
}

if (!deploy_helpers.isNullUndefinedOrEmptyString(mode)) {
putOpts['mode'] = mode;
if (deploy_helpers.isNullUndefinedOrEmptyString(mode)) {
mode = undefined;
}

return mode;
};

let putOpts: any = {};
putOpts['mode'] = getModeValue(targetFile);
if (deploy_helpers.toBooleanSafe(target.updateModesOfDirectories)) {
putOpts['dirMode'] = getModeValue(targetDirectory);
}

// upload the file
Expand Down Expand Up @@ -776,10 +786,31 @@ class SFtpPlugin extends deploy_objects.DeployPluginWithContextBase<SFTPContext>
});
}

let changeModForDirectory = (initDirCache?: boolean) => {
if (ctx.hasCancelled) {
completed(); // cancellation requested
return;
}

if (deploy_helpers.isNullUndefinedOrEmptyString(putOpts['dirMode'])) {
uploadFile(initDirCache);
}
else {
ctx.connection.sftp.chmod(targetDirectory, putOpts['dirMode'], (err) => {
if (err) {
completed(err);
}
else {
uploadFile(initDirCache);
}
});
}
};

if (deploy_helpers.isNullOrUndefined(ctx.cachedRemoteDirectories[targetDirectory])) {
// first check if target directory exists
ctx.connection.list(targetDirectory).then(() => {
uploadFile(true);
changeModForDirectory(true);
}).catch((err) => {
// no => try to create

Expand All @@ -789,14 +820,14 @@ class SFtpPlugin extends deploy_objects.DeployPluginWithContextBase<SFTPContext>
}

ctx.connection.mkdir(targetDirectory, true).then(() => {
uploadFile(true);
changeModForDirectory(true);
}).catch((err) => {
completed(err);
});
});
}
else {
uploadFile();
changeModForDirectory();
}
}
}
Expand Down

0 comments on commit 55902c3

Please sign in to comment.