Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
9bbd9b06
Commit
9bbd9b06
authored
9 years ago
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
give ipfs get symlink support
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
d993bc04
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
10 deletions
+28
-10
core/commands/add.go
core/commands/add.go
+0
-4
thirdparty/tar/extractor.go
thirdparty/tar/extractor.go
+17
-6
unixfs/archive/tar/writer.go
unixfs/archive/tar/writer.go
+11
-0
No files found.
core/commands/add.go
View file @
9bbd9b06
...
...
@@ -143,7 +143,6 @@ remains to be implemented.
return
nil
// done
}
log
.
Errorf
(
"FILE: %#v"
,
file
)
if
_
,
err
:=
fileAdder
.
addFile
(
file
);
err
!=
nil
{
return
err
}
...
...
@@ -361,9 +360,6 @@ func (params *adder) addFile(file files.File) (*dag.Node, error) {
}
if
s
,
ok
:=
file
.
(
*
files
.
Symlink
);
ok
{
log
.
Error
(
"SYMLINK: "
,
s
)
log
.
Error
(
s
.
Target
)
log
.
Error
(
s
.
FileName
())
dagnode
:=
&
dag
.
Node
{
Data
:
ft
.
SymlinkData
(
s
.
Target
),
}
...
...
This diff is collapsed.
Click to expand it.
thirdparty/tar/extractor.go
View file @
9bbd9b06
...
...
@@ -2,6 +2,7 @@ package tar
import
(
"archive/tar"
"fmt"
"io"
"os"
gopath
"path"
...
...
@@ -39,15 +40,21 @@ func (te *Extractor) Extract(reader io.Reader) error {
break
}
if
header
.
Typeflag
==
tar
.
TypeDir
{
switch
header
.
Typeflag
{
case
tar
.
TypeDir
:
if
err
:=
te
.
extractDir
(
header
,
i
);
err
!=
nil
{
return
err
}
continue
}
if
err
:=
te
.
extractFile
(
header
,
tarReader
,
i
,
rootExists
,
rootIsDir
);
err
!=
nil
{
return
err
case
tar
.
TypeReg
:
if
err
:=
te
.
extractFile
(
header
,
tarReader
,
i
,
rootExists
,
rootIsDir
);
err
!=
nil
{
return
err
}
case
tar
.
TypeSymlink
:
if
err
:=
te
.
extractSymlink
(
header
);
err
!=
nil
{
return
err
}
default
:
return
fmt
.
Errorf
(
"unrecognized tar header type: %d"
,
header
.
Typeflag
)
}
}
return
nil
...
...
@@ -79,6 +86,10 @@ func (te *Extractor) extractDir(h *tar.Header, depth int) error {
return
nil
}
func
(
te
*
Extractor
)
extractSymlink
(
h
*
tar
.
Header
)
error
{
return
os
.
Symlink
(
h
.
Linkname
,
te
.
outputPath
(
h
.
Name
))
}
func
(
te
*
Extractor
)
extractFile
(
h
*
tar
.
Header
,
r
*
tar
.
Reader
,
depth
int
,
rootExists
bool
,
rootIsDir
bool
)
error
{
path
:=
te
.
outputPath
(
h
.
Name
)
...
...
This diff is collapsed.
Click to expand it.
unixfs/archive/tar/writer.go
View file @
9bbd9b06
...
...
@@ -79,6 +79,8 @@ func (w *Writer) WriteNode(nd *mdag.Node, fpath string) error {
fallthrough
case
upb
.
Data_File
:
return
w
.
writeFile
(
nd
,
pb
,
fpath
)
case
upb
.
Data_Symlink
:
return
writeSymlinkHeader
(
w
.
TarW
,
string
(
pb
.
GetData
()),
fpath
)
default
:
return
ft
.
ErrUnrecognizedType
}
...
...
@@ -108,3 +110,12 @@ func writeFileHeader(w *tar.Writer, fpath string, size uint64) error {
// TODO: set mode, dates, etc. when added to unixFS
})
}
func
writeSymlinkHeader
(
w
*
tar
.
Writer
,
target
,
fpath
string
)
error
{
return
w
.
WriteHeader
(
&
tar
.
Header
{
Name
:
fpath
,
Linkname
:
target
,
Mode
:
0777
,
Typeflag
:
tar
.
TypeSymlink
,
})
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
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