Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nagy Tibor
extrautils
Commits
90a03741
Commit
90a03741
authored
Aug 13, 2017
by
Bryan Blanchard
Browse files
Read symlinks from tar header and recreate
parent
5fade3cf
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/bin/tar.rs
View file @
90a03741
...
...
@@ -8,7 +8,7 @@ extern crate libflate;
use
std
::{
env
,
process
};
use
std
::
io
::{
stdin
,
stdout
,
stderr
,
copy
,
Error
,
ErrorKind
,
Result
,
Read
,
Write
,
BufReader
};
use
std
::
fs
::{
self
,
File
};
use
std
::
os
::
unix
::
fs
::
OpenOptionsExt
;
use
std
::
os
::
unix
::
fs
::
{
OpenOptionsExt
,
symlink
}
;
use
std
::
path
::{
Path
,
PathBuf
};
use
std
::
str
::
FromStr
;
...
...
@@ -61,6 +61,14 @@ fn list(tar: &str) -> Result<()> {
}
}
fn
create_symlink
(
link
:
PathBuf
,
target
:
&
Path
)
->
Result
<
()
>
{
//delete existing file to make way for symlink
if
link
.exists
()
{
fs
::
remove_file
(
link
.clone
())
.expect
(
&
format!
(
"could not overwrite: {:?}"
,
link
));
}
symlink
(
target
,
link
)
}
fn
extract_inner
<
T
:
Read
>
(
ar
:
&
mut
Archive
<
T
>
,
verbose
:
bool
,
strip
:
usize
)
->
Result
<
()
>
{
for
entry_result
in
try
!
(
ar
.entries
())
{
let
mut
entry
=
try
!
(
entry_result
);
...
...
@@ -99,6 +107,11 @@ fn extract_inner<T: Read>(ar: &mut Archive<T>, verbose: bool, strip: usize) -> R
EntryType
::
Directory
=>
{
try
!
(
fs
::
create_dir_all
(
&
path
));
},
EntryType
::
Symlink
=>
{
if
let
Some
(
target
)
=
entry
.link_name
()
.expect
(
&
format!
(
"Can't parse symlink target for: {:?}"
,
path
))
{
try
!
(
create_symlink
(
path
,
&
target
))
}
},
other
=>
{
panic!
(
"Unsupported entry type {:?}"
,
other
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment