-
Notifications
You must be signed in to change notification settings - Fork 30
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
feat: support unixfs metadata and formatting it #14
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
970ae19
feat: support unixfs metadata and formatting it
achingbrain 47d0527
test: add tests
achingbrain b1ea304
fix: handle nested dirs better
achingbrain 66c4137
chore: change dep used
achingbrain c11b4ab
refactor: make test more readable
achingbrain 0d6caaf
Merge remote-tracking branch 'origin/master' into support-unixfs-meta…
achingbrain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'use strict' | ||
|
||
const S_ISUID = parseInt('4000', 8) // set UID bit | ||
const S_ISGID = parseInt('2000', 8) // set-group-ID bit (see below) | ||
const S_ISVTX = parseInt('1000', 8) // sticky bit (see below) | ||
// const S_IRWXU = parseInt('700', 8) // mask for file owner permissions | ||
const S_IRUSR = parseInt('400', 8) // owner has read permission | ||
const S_IWUSR = parseInt('200', 8) // owner has write permission | ||
const S_IXUSR = parseInt('100', 8) // owner has execute permission | ||
// const S_IRWXG = parseInt('70', 8) // mask for group permissions | ||
const S_IRGRP = parseInt('40', 8) // group has read permission | ||
const S_IWGRP = parseInt('20', 8) // group has write permission | ||
const S_IXGRP = parseInt('10', 8) // group has execute permission | ||
// const S_IRWXO = parseInt('7', 8) // mask for permissions for others (not in group) | ||
const S_IROTH = parseInt('4', 8) // others have read permission | ||
const S_IWOTH = parseInt('2', 8) // others have write permission | ||
const S_IXOTH = parseInt('1', 8) // others have execute permission | ||
|
||
function checkPermission (mode, perm, type, output) { | ||
if ((mode & perm) === perm) { | ||
output.push(type) | ||
} else { | ||
output.push('-') | ||
} | ||
} | ||
|
||
function formatMode (mode, isDirectory) { | ||
const output = [] | ||
|
||
if (isDirectory) { | ||
output.push('d') | ||
} else { | ||
output.push('-') | ||
} | ||
|
||
checkPermission(mode, S_IRUSR, 'r', output) | ||
checkPermission(mode, S_IWUSR, 'w', output) | ||
|
||
if ((mode & S_ISUID) === S_ISUID) { | ||
output.push('s') | ||
} else { | ||
checkPermission(mode, S_IXUSR, 'x', output) | ||
} | ||
|
||
checkPermission(mode, S_IRGRP, 'r', output) | ||
checkPermission(mode, S_IWGRP, 'w', output) | ||
|
||
if ((mode & S_ISGID) === S_ISGID) { | ||
output.push('s') | ||
} else { | ||
checkPermission(mode, S_IXGRP, 'x', output) | ||
} | ||
|
||
checkPermission(mode, S_IROTH, 'r', output) | ||
checkPermission(mode, S_IWOTH, 'w', output) | ||
|
||
if ((mode & S_ISVTX) === S_ISVTX) { | ||
output.push('t') | ||
} else { | ||
checkPermission(mode, S_IXOTH, 'x', output) | ||
} | ||
|
||
return output.join('') | ||
} | ||
|
||
module.exports = formatMode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict' | ||
|
||
function formatMtime (mtime) { | ||
if (mtime === undefined) { | ||
return '-' | ||
} | ||
|
||
return new Date(mtime * 1000).toLocaleDateString(Intl.DateTimeFormat().resolvedOptions().locale, { | ||
year: 'numeric', | ||
month: 'short', | ||
day: 'numeric', | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
second: '2-digit', | ||
timeZoneName: 'short' | ||
}) | ||
} | ||
|
||
module.exports = formatMtime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 the future we might get some perf wins by parallel mapping these.
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.
Possibly - our bottlenecks typically aren't from reading paths from the filesystem but it's worth measuring before jumping to conclusions. Like I just did.