Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
1fb90ad6
Unverified
提交
1fb90ad6
authored
3月 23, 2018
作者:
Whyrusleeping
提交者:
GitHub
3月 23, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4857 from ipfs/extract/thirdparty-tar
Extract: thirdparty/tar
上级
8dbdb295
9a2f2976
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
7 行增加
和
133 行删除
+7
-133
get.go
core/commands/get.go
+1
-1
package.json
package.json
+6
-0
extractor.go
thirdparty/tar/extractor.go
+0
-132
没有找到文件。
core/commands/get.go
浏览文件 @
1fb90ad6
...
@@ -13,9 +13,9 @@ import (
...
@@ -13,9 +13,9 @@ import (
e
"github.com/ipfs/go-ipfs/core/commands/e"
e
"github.com/ipfs/go-ipfs/core/commands/e"
dag
"github.com/ipfs/go-ipfs/merkledag"
dag
"github.com/ipfs/go-ipfs/merkledag"
path
"github.com/ipfs/go-ipfs/path"
path
"github.com/ipfs/go-ipfs/path"
tar
"github.com/ipfs/go-ipfs/thirdparty/tar"
uarchive
"github.com/ipfs/go-ipfs/unixfs/archive"
uarchive
"github.com/ipfs/go-ipfs/unixfs/archive"
tar
"gx/ipfs/QmYk64JEF4QWPB9Kqib63g8vfYfv78AmSUyeFaMaX6F9vQ/tar-utils"
"gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
"gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
"gx/ipfs/QmeWjRodbcZFKe5tMN7poEx3izym6osrLSnTLf9UjJZBbs/pb"
"gx/ipfs/QmeWjRodbcZFKe5tMN7poEx3izym6osrLSnTLf9UjJZBbs/pb"
"gx/ipfs/QmfAkMSt9Fwzk48QDJecPcwCUjnf2uG7MLnmCGTp4C6ouL/go-ipfs-cmds"
"gx/ipfs/QmfAkMSt9Fwzk48QDJecPcwCUjnf2uG7MLnmCGTp4C6ouL/go-ipfs-cmds"
...
...
package.json
浏览文件 @
1fb90ad6
...
@@ -575,6 +575,12 @@
...
@@ -575,6 +575,12 @@
"hash"
:
"QmdbxjQWogRCHRaxhhGnYdT1oQJzL9GdqSKzCdqWr85AP2"
,
"hash"
:
"QmdbxjQWogRCHRaxhhGnYdT1oQJzL9GdqSKzCdqWr85AP2"
,
"name"
:
"pubsub"
,
"name"
:
"pubsub"
,
"version"
:
"1.0.0"
"version"
:
"1.0.0"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"QmYk64JEF4QWPB9Kqib63g8vfYfv78AmSUyeFaMaX6F9vQ"
,
"name"
:
"tar-utils"
,
"version"
:
"0.0.2"
}
}
],
],
"gxVersion"
:
"0.10.0"
,
"gxVersion"
:
"0.10.0"
,
...
...
thirdparty/tar/extractor.go
deleted
100644 → 0
浏览文件 @
8dbdb295
package
tar
import
(
"archive/tar"
"fmt"
"io"
"os"
gopath
"path"
fp
"path/filepath"
"strings"
)
type
Extractor
struct
{
Path
string
Progress
func
(
int64
)
int64
}
func
(
te
*
Extractor
)
Extract
(
reader
io
.
Reader
)
error
{
tarReader
:=
tar
.
NewReader
(
reader
)
// Check if the output path already exists, so we know whether we should
// create our output with that name, or if we should put the output inside
// a preexisting directory
rootExists
:=
true
rootIsDir
:=
false
if
stat
,
err
:=
os
.
Stat
(
te
.
Path
);
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
rootExists
=
false
}
else
if
err
!=
nil
{
return
err
}
else
if
stat
.
IsDir
()
{
rootIsDir
=
true
}
// files come recursively in order (i == 0 is root directory)
for
i
:=
0
;
;
i
++
{
header
,
err
:=
tarReader
.
Next
()
if
err
!=
nil
&&
err
!=
io
.
EOF
{
return
err
}
if
header
==
nil
||
err
==
io
.
EOF
{
break
}
switch
header
.
Typeflag
{
case
tar
.
TypeDir
:
if
err
:=
te
.
extractDir
(
header
,
i
);
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
}
// outputPath returns the path at whicht o place tarPath
func
(
te
*
Extractor
)
outputPath
(
tarPath
string
)
string
{
elems
:=
strings
.
Split
(
tarPath
,
"/"
)
// break into elems
elems
=
elems
[
1
:
]
// remove original root
path
:=
fp
.
Join
(
elems
...
)
// join elems
path
=
fp
.
Join
(
te
.
Path
,
path
)
// rebase on extractor root
return
path
}
func
(
te
*
Extractor
)
extractDir
(
h
*
tar
.
Header
,
depth
int
)
error
{
path
:=
te
.
outputPath
(
h
.
Name
)
if
depth
==
0
{
// if this is the root root directory, use it as the output path for remaining files
te
.
Path
=
path
}
return
os
.
MkdirAll
(
path
,
0755
)
}
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
)
if
depth
==
0
{
// if depth is 0, this is the only file (we aren't 'ipfs get'ing a directory)
if
rootExists
&&
rootIsDir
{
// putting file inside of a root dir.
fnameo
:=
gopath
.
Base
(
h
.
Name
)
fnamen
:=
fp
.
Base
(
path
)
// add back original name if lost.
if
fnameo
!=
fnamen
{
path
=
fp
.
Join
(
path
,
fnameo
)
}
}
// else if old file exists, just overwrite it.
}
file
,
err
:=
os
.
Create
(
path
)
if
err
!=
nil
{
return
err
}
defer
file
.
Close
()
return
copyWithProgress
(
file
,
r
,
te
.
Progress
)
}
func
copyWithProgress
(
to
io
.
Writer
,
from
io
.
Reader
,
cb
func
(
int64
)
int64
)
error
{
buf
:=
make
([]
byte
,
4096
)
for
{
n
,
err
:=
from
.
Read
(
buf
)
if
n
!=
0
{
cb
(
int64
(
n
))
_
,
err2
:=
to
.
Write
(
buf
[
:
n
])
if
err2
!=
nil
{
return
err2
}
}
if
err
!=
nil
{
if
err
==
io
.
EOF
{
return
nil
}
return
err
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论