-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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 directory type #6905
fix directory type #6905
Conversation
std/archive/tar.ts
Outdated
@@ -383,7 +387,7 @@ export class Tar { | |||
fileSize: pad(fileSize, 11), | |||
mtime: pad(mtime, 11), | |||
checksum: " ", | |||
type: "0", // just a file | |||
type: info?.isDirectory ?? opts.type === "directory" ? "5" : "0", |
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.
Isn’t there an enum that can be used here? The value “5” and “0” are not very descriptive. (I see that it was using “0” before but that seems like bad code. Now would be a good opportunity to clean this up.)
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 have updated the code, but I am not sure if it is appropriate.
I referenced some websites, and I add "fifo" and "contiguous-file" into Types
https://github.com/mafintosh/tar-stream
http://www.gnu.org/software/tar/manual/html_node/Standard.html
"directory" = 5, | ||
"fifo" = 6, | ||
"contiguous-file" = 7, | ||
} |
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.
If the value is only used as a string why not use a string here?
enum Types {
"file" = "0",
"link" = "1",
// ...
}
I suggest "FileTypes" instead of "Types" - just a bit less ambiguous.
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.
in method #getMetadata of Class Untar, convert a numeric string to string, such as "0" => "file"
// before
meta.type = types[meta.type as string] || meta.type;
// now
meta.type = FileTypes[parseInt(meta.type!)] ?? meta.type;
if the value is string, i get an error
enum FileTypes {
"file" = "0",
"link" = 1,
}
console.log(FileTypes.file);
// ok
console.log(FileTypes[1]);
// throw an error: Element implicitly has an 'any' type because index expression is not of type 'number'.ts(7015)
console.log(FileTypes["0"]);
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.
LGTM - thanks @fuxingZhang
I use tar.append to add a folder and I get incorrect entry.type.