-
Notifications
You must be signed in to change notification settings - Fork 190
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
builder: add support for archiving special files on Unix #246
Conversation
af50eea
to
1d5d533
Compare
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.
Seems reasonable enough to me, thanks!
Could this perhaps be refactored a bit though to avoid a few extra calls to fs::metadata
being called? I think this could have an internal append function which takes a FileType
from libstd and dispatches internally about how to append it? (e.g. more cases would be handled on Unix than on Windows, but regular files would all roughly be handled in the same place)
Sorry for the late reply. I am a bit confused by this suggestion: I saw the Line 542 in f07b3c1
stat() should be fine here? https://github.com/alexcrichton/tar-rs/pull/246/files#diff-e4f794ca308aa712cbad31feb714df7cada1bbe453a30e232e45891571430263R607
Did you mean to refactor the |
I mostly just got the feeling reading this that it'd be better to refactor where at some point there's the equivalent of a |
src/builder.rs
Outdated
// In case of a symlink pointing to a directory, is_dir is false, but src.is_dir() will return true | ||
if is_dir || (is_symlink && follow && src.is_dir()) { | ||
for entry in fs::read_dir(&src)? { | ||
let entry = entry?; | ||
let file_type = entry.file_type()?; | ||
stack.push((entry.path(), file_type.is_dir(), file_type.is_symlink())); | ||
let metadata = entry.metadata()?; |
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 unfortunately has a side effect where on platforms like Unix this ends up doing a syscall whereas previously accessing file_type
generally doesn't require a syscall on most major platforms. The intention was that this loop should primarily only do fs::read_dir
as a sycall and otherwise other syscalls can be avoided.
My thinking about refactoring this was largely that this loop has one iteration of "look at the file type and delegate appropriately" but above in append_path_with_name
it's basically the same loop. With the append_path_with_name
addition it's getting more complicated so I was wondering if it would be possible to refactor this loop and append_path_with_name
above to call a common function which is the one location where special files are handled.
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 unfortunately has a side effect where on platforms like Unix this ends up doing a syscall whereas previously accessing
file_type
generally doesn't require a syscall on most major platforms. The intention was that this loop should primarily only dofs::read_dir
as a sycall and otherwise other syscalls can be avoided.
I have reverted the changes made to this loop.
My thinking about refactoring this was largely that this loop has one iteration of "look at the file type and delegate appropriately" but above in
append_path_with_name
it's basically the same loop. With theappend_path_with_name
addition it's getting more complicated so I was wondering if it would be possible to refactor this loop andappend_path_with_name
above to call a common function which is the one location where special files are handled.
I am not quite sure which one is better:
- Make a new delegate function
append_special
and rename the currentappend_special
toappend_special_unix
. Then in theappend_special
function, usefs::metadata
to get the metadata and pass it toappend_special_unix
. In which case, the loop needs to be modified to differentiate a regular file from a special one. - Similar to (1) but instead of using
fs::metadata
in that function,fs::metadata
is used in the "special file" branch of the loop. The advantage of this is one lessstat
when called fromappend_path_with_name
(since there is onestat
in that function as well). - Similar to (1) but making
append_special
to acceptOption<fs::metadata>
andstat
on-demand.
Added support for archiving character, block and fifo files on Unix, this is useful when you want to take a whole system backup or re-archiving an extracted system image
* attempt to reduce `stat` calls
Ping? Is there any update for this Pull Request? |
Sorry I think this got lost in my inbox, but this looks good to me now! |
Added support for archiving character, block and FIFO files on Unix, this is useful when you want to take a whole system backup or re-archiving an extracted system image.
The file handling in this pull request isn't particularly graceful since I am not very experienced with the codebase, any suggestions are welcome!
This change is