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
28df97e5
Commit
28df97e5
authored
Sep 03, 2015
by
Juan Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1629 from rht/localize-os-open
serialfile: localize os.Open into NewSerialFile
parents
9c40bf1e
0c95ed6b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
26 deletions
+20
-26
commands/cli/parse.go
commands/cli/parse.go
+1
-16
commands/files/serialfile.go
commands/files/serialfile.go
+12
-4
core/coreunix/add.go
core/coreunix/add.go
+4
-4
importer/importer.go
importer/importer.go
+3
-2
No files found.
commands/cli/parse.go
View file @
28df97e5
...
...
@@ -356,21 +356,6 @@ func appendFile(args []files.File, inputs []string, argDef *cmds.Argument, recur
return
nil
,
nil
,
err
}
if
stat
.
Mode
()
&
os
.
ModeSymlink
!=
0
{
target
,
err
:=
os
.
Readlink
(
fpath
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
arg
:=
files
.
NewLinkFile
(
""
,
fpath
,
target
,
stat
)
return
append
(
args
,
arg
),
inputs
[
1
:
],
nil
}
file
,
err
:=
os
.
Open
(
fpath
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
if
stat
.
IsDir
()
{
if
!
argDef
.
Recursive
{
err
=
fmt
.
Errorf
(
"Invalid path '%s', argument '%s' does not support directories"
,
...
...
@@ -384,7 +369,7 @@ func appendFile(args []files.File, inputs []string, argDef *cmds.Argument, recur
}
}
arg
,
err
:=
files
.
NewSerialFile
(
path
.
Base
(
fpath
),
fpath
,
file
)
arg
,
err
:=
files
.
NewSerialFile
(
path
.
Base
(
fpath
),
fpath
,
stat
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
...
...
commands/files/serialfile.go
View file @
28df97e5
...
...
@@ -25,8 +25,17 @@ type serialFile struct {
current
*
os
.
File
}
func
NewSerialFile
(
name
,
path
string
,
file
*
os
.
File
)
(
File
,
error
)
{
stat
,
err
:=
file
.
Stat
()
func
NewSerialFile
(
name
,
path
string
,
stat
os
.
FileInfo
)
(
File
,
error
)
{
if
stat
.
Mode
()
&
os
.
ModeSymlink
!=
0
{
target
,
err
:=
os
.
Readlink
(
path
)
if
err
!=
nil
{
return
nil
,
err
}
return
NewLinkFile
(
""
,
path
,
target
,
stat
),
nil
}
file
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -49,8 +58,7 @@ func newSerialFile(name, path string, file *os.File, stat os.FileInfo) (File, er
// we no longer need our root directory file (we already statted the contents),
// so close it
err
=
file
.
Close
()
if
err
!=
nil
{
if
err
:=
file
.
Close
();
err
!=
nil
{
return
nil
,
err
}
...
...
core/coreunix/add.go
View file @
28df97e5
...
...
@@ -43,18 +43,18 @@ func Add(n *core.IpfsNode, r io.Reader) (string, error) {
// AddR recursively adds files in |path|.
func
AddR
(
n
*
core
.
IpfsNode
,
root
string
)
(
key
string
,
err
error
)
{
f
,
err
:=
os
.
Open
(
root
)
stat
,
err
:=
os
.
Lstat
(
root
)
if
err
!=
nil
{
return
""
,
err
}
defer
f
.
Close
()
f
f
,
err
:=
files
.
NewSerialFile
(
root
,
root
,
f
)
f
,
err
:=
files
.
NewSerialFile
(
root
,
root
,
stat
)
if
err
!=
nil
{
return
""
,
err
}
defer
f
.
Close
()
dagnode
,
err
:=
addFile
(
n
,
f
f
)
dagnode
,
err
:=
addFile
(
n
,
f
)
if
err
!=
nil
{
return
""
,
err
}
...
...
importer/importer.go
View file @
28df97e5
...
...
@@ -6,6 +6,7 @@ import (
"fmt"
"os"
"github.com/ipfs/go-ipfs/commands/files"
bal
"github.com/ipfs/go-ipfs/importer/balanced"
"github.com/ipfs/go-ipfs/importer/chunk"
h
"github.com/ipfs/go-ipfs/importer/helpers"
...
...
@@ -20,7 +21,7 @@ var log = u.Logger("importer")
// Builds a DAG from the given file, writing created blocks to disk as they are
// created
func
BuildDagFromFile
(
fpath
string
,
ds
dag
.
DAGService
,
mp
pin
.
ManualPinner
)
(
*
dag
.
Node
,
error
)
{
stat
,
err
:=
os
.
S
tat
(
fpath
)
stat
,
err
:=
os
.
Ls
tat
(
fpath
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -29,7 +30,7 @@ func BuildDagFromFile(fpath string, ds dag.DAGService, mp pin.ManualPinner) (*da
return
nil
,
fmt
.
Errorf
(
"`%s` is a directory"
,
fpath
)
}
f
,
err
:=
os
.
Open
(
fpath
)
f
,
err
:=
files
.
NewSerialFile
(
fpath
,
fpath
,
stat
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
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