Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/windows-glob-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
njpanderson committed Aug 28, 2018
2 parents 26a59bb + 88c16ca commit 23644ef
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Push Changelog
All notable changes to Push will be documented in this file. If this file has appeared within Visual Studio Code, it means that Push has had a notable update. You can easily disable this feature by setting the `njpPush.showChangelog` to `false`.

## 0.5.1
- Fixed path detection and handling for certain cases in Windows. Sorry, Windows users! (Thanks, Matt!)

## 0.5.0
- Add support for environments within service configs. This is a big feature, please check the README!
- Altered the settingsFile configuration somewhat. New service settings files will be named `.push.settings.jsonc` to signify that they can contain comments. Your current service files will still work with the old filename, but if you have customised the filename, please take note of this setting and its partner setting, `settingsFileGlob`.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "push",
"displayName": "Push",
"description": "SFTP and File based uploading",
"version": "0.5.0",
"version": "0.5.1",
"publisher": "njp-anderson",
"engines": {
"vscode": "^1.22.0"
Expand Down
5 changes: 3 additions & 2 deletions src/Push.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,9 @@ class Push extends PushBase {
// Settings retrieved from JSON file within context
newConfig.env = settings.data.env;
newConfig.serviceName = settings.data.service;
newConfig.serviceFilename = settings.file,
newConfig.service = settings.data[newConfig.serviceName];
newConfig.serviceFilename = settings.file;
newConfig.serviceUri = settings.uri;
newConfig.service = settings.data[newConfig.serviceName];
newConfig.serviceSettingsHash = settings.hash;

// Expand environment variables
Expand Down
35 changes: 20 additions & 15 deletions src/lib/Paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const glob = require('glob');

const ExtendedStream = require('./ExtendedStream');
const PathCache = require('../lib/PathCache');
const PushError = require('../lib/PushError');

class Paths {
fileExists(file) {
Expand Down Expand Up @@ -204,8 +203,6 @@ class Paths {
* @param {array} [ignoreGlobs] - List of globs to ignore.
*/
getDirectoryContentsAsFiles(include, ignoreGlobs = [], followSymlinks = false) {
let parsed;

if (include instanceof vscode.Uri) {
// Create path out of Uri
include = `${this.getNormalPath(include)}${path.sep}**`;
Expand All @@ -216,14 +213,9 @@ class Paths {
include = path.join.apply(path, include);
}

include = (include.split(path.sep)).join('/');
parsed = path.parse(include);

include = include.replace(parsed.root, '/');

return new Promise((resolve, reject) => {
new glob.Glob(
include,
this.ensureGlobPath(include),
this.getGlobOptions({
ignore: ignoreGlobs,
follow: followSymlinks
Expand All @@ -246,7 +238,7 @@ class Paths {
}

new glob.Glob(
`${this.getNormalPath(uri)}`,
`${this.ensureGlobPath(uri)}`,
this.getGlobOptions({
ignore: ignoreGlobs
}),
Expand Down Expand Up @@ -289,7 +281,7 @@ class Paths {
* the root of the active workspace is reached.
* @param {string} file - The filename to look for. Supports globs.
* @param {string} startDir - The directory to start looking in.
* @returns {string|null} - Either the matched filename, or `null`.
* @returns {Uri|null} - Either the matched Uri, or `null`.
*/
findFileInAncestors(file, startDir) {
let matches,
Expand All @@ -302,19 +294,22 @@ class Paths {
};

// while (!fs.existsSync(startDir + path.sep + file)) {
while (!(matches = (glob.sync(startDir + path.sep + file, globOptions))).length) {
// console.log(glob.sync(startDir + path.sep + file));
while (!(matches = (glob.sync(
this.ensureGlobPath(startDir + path.sep + file),
globOptions
))).length) {
if (rootPaths.indexOf(startDir) !== -1 || loop === 50) {
// dir matches any root paths or hard loop limit reached
return null;
}

// Strip off directory basename
startDir = startDir.substring(0, startDir.lastIndexOf(path.sep));
startDir = path.dirname(startDir);
// startDir = startDir.substring(0, startDir.lastIndexOf('/'));
loop += 1;
}

return matches[0];
return vscode.Uri.file(matches[0]);
}

/**
Expand Down Expand Up @@ -465,6 +460,16 @@ class Paths {
});
});
}

/**
* Ensures a path can be used with glob (even on windows)
* @param {string} pathName - The path to make glob 'friendly'
*/
ensureGlobPath(pathName) {
pathName = this.getNormalPath(pathName);
pathName = pathName.replace(/\\/g, '/');
return pathName;
}
}

Paths.sep = path.sep;
Expand Down
5 changes: 3 additions & 2 deletions src/lib/ServiceSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ class ServiceSettings {

getServerFile(dir, settingsFilename) {
// Find the settings file
let file = this.paths.findFileInAncestors(
let file = this.paths.getNormalPath(this.paths.findFileInAncestors(
settingsFilename,
dir
);
));

if (file !== '' && fs.existsSync(file)) {
// File isn't empty and exists - read and set into cache
Expand Down Expand Up @@ -187,6 +187,7 @@ class ServiceSettings {
// Cache entry
this.settingsCache[uriPath] = {
file: settings.file,
uri: vscode.Uri.file(settings.file),
fileContents: settings.contents,
newFile,
data,
Expand Down

0 comments on commit 23644ef

Please sign in to comment.