-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix path separator used by normalizeTarEntry() under Windows #8
Conversation
41fac9e
to
9481089
Compare
I've just force-pushed a complete replacement of the previous code, because when I actually tested it on Windows, it failed. @zvin and others, apologies for having placed the original PR for review before having tested it on Windows (luckily it was a very small change...). What is now up for review has been tested on Windows and MacOS. Thanks! |
9481089
to
5e0d2fd
Compare
OK, one more change. The tests were passing on Windows and MacOS, yes, but then I thought of additional test cases which were failing on all platforms:
(At least some of those were failing.) Also I have added removal of any trailing slashes. The purpose of normalization is to provide a single representation for multiple ways of referring to the same entity, so for example directories I think the trailing slash removal, however, could be seen as a breaking change (?), and for this reason I have set the change-type to 'major'. |
lib/index.ts
Outdated
} | ||
let normalized = normalize(name); | ||
// remove any leading or trailing slashes | ||
if (normalized.startsWith('/')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how much other code in here would benefit from lodash
, but certainly return _.trim(normalized, '/')
would save the next 7 lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! There was also a global noop
function that I have now replaced with _.noop
. (In the past I thought that noop
alone wasn't enough reason to add lodash as a dependency, but _.trim
tipped the balance for me.) :-)
lib/index.ts
Outdated
* Borrowed from: | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions | ||
*/ | ||
function escapeRE(s: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess lodash
would be useful then, as there's a _.escapeRegExp()
method that does exactly this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, after @zvin's comment, it turns out I don't need a regular expression at all...
lib/index.ts
Outdated
*/ | ||
function normalizeNonPosix(p: string): string { | ||
return path.normalize(p).replace(pathSepRE, '/'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use path.posix.normalize
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What?!? Where did that come from?! I had just saved several lines of code using lodash following @hedss comment, now I can delete a couple more functions too. What next? I guess if I just wait another half an hour, someone else will add a comment: "oh, you're using tar-utils
? you don't need that, just import genie
and you're done!" or maybe: "oh, all of that to fix the CLI under Windows? you don't need the CLI, just say 'Siri, push the app to balena' and it's all sorted".
LOL :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, we're not using python https://xkcd.com/353/ :)
normalizeTarEntry() now also removes trailing slashes, reason why the change-type is major. Connects-to: balena-io/balena-cli#1133 Change-type: major Signed-off-by: Paulo Castro <paulo@balena.io>
5e0d2fd
to
7aaa906
Compare
stream.removeListener('end', onEnd || noop); | ||
stream.removeListener('data', onData || _.noop); | ||
stream.removeListener('error', onError || _.noop); | ||
stream.removeListener('end', onEnd || _.noop); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that lodash
was added as a dependency, might as well use its _.noop
.
@@ -124,7 +150,7 @@ describe('multicastStream', function() { | |||
const nStreams = 3; | |||
for (let i = 0; i < nStreams; ++i) { | |||
toStreams.push( | |||
new MockWritable({ highWaterMark: hwm / (i + 1) }, i * 10), | |||
new MockWritable({ highWaterMark: Math.ceil(hwm / (i + 1)) }, i * 10), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change prevents a non-integer highWaterMark
value like 16384 / 3 = 5461.3. Oddly the test was passing under MacOS and Linux, but failing under Windows.
Connects-to: balena-io/balena-cli#1133
Change-type: patch
Signed-off-by: Paulo Castro paulo@balena.io