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
0718bd73
Commit
0718bd73
authored
Mar 14, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix locking
parent
eb228eb6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
16 deletions
+15
-16
ipnsfs/dir.go
ipnsfs/dir.go
+15
-16
No files found.
ipnsfs/dir.go
View file @
0718bd73
...
...
@@ -70,7 +70,6 @@ func (d *Directory) Open(tpath []string, mode int) (*File, error) {
return
dir
.
Open
(
tpath
[
1
:
],
mode
)
}
// consider combining into a single method...
type
childCloser
interface
{
closeChild
(
string
,
*
dag
.
Node
)
error
}
...
...
@@ -82,18 +81,16 @@ func (d *Directory) closeChild(name string, nd *dag.Node) error {
}
d
.
lock
.
Lock
()
defer
d
.
lock
.
Unlock
()
err
=
d
.
node
.
RemoveNodeLink
(
name
)
if
err
!=
nil
&&
err
!=
dag
.
ErrNotFound
{
d
.
lock
.
Unlock
()
return
err
}
err
=
d
.
node
.
AddNodeLinkClean
(
name
,
nd
)
if
err
!=
nil
{
d
.
lock
.
Unlock
()
return
err
}
d
.
lock
.
Unlock
()
return
d
.
parent
.
closeChild
(
d
.
name
,
d
.
node
)
}
...
...
@@ -179,6 +176,10 @@ func (d *Directory) childDir(name string) (*Directory, error) {
func
(
d
*
Directory
)
Child
(
name
string
)
(
FSNode
,
error
)
{
d
.
lock
.
Lock
()
defer
d
.
lock
.
Unlock
()
return
d
.
childUnsync
(
name
)
}
func
(
d
*
Directory
)
childUnsync
(
name
string
)
(
FSNode
,
error
)
{
dir
,
err
:=
d
.
childDir
(
name
)
if
err
==
nil
{
return
dir
,
nil
...
...
@@ -204,54 +205,50 @@ func (d *Directory) List() []string {
func
(
d
*
Directory
)
Mkdir
(
name
string
)
(
*
Directory
,
error
)
{
d
.
lock
.
Lock
()
defer
d
.
lock
.
Unlock
()
_
,
err
:=
d
.
childDir
(
name
)
if
err
==
nil
{
d
.
lock
.
Unlock
()
return
nil
,
errors
.
New
(
"directory by that name already exists"
)
return
nil
,
os
.
ErrExist
}
_
,
err
=
d
.
childFile
(
name
)
if
err
==
nil
{
d
.
lock
.
Unlock
()
return
nil
,
errors
.
New
(
"file by that name already exists"
)
return
nil
,
os
.
ErrExist
}
ndir
:=
&
dag
.
Node
{
Data
:
ft
.
FolderPBData
()}
err
=
d
.
node
.
AddNodeLinkClean
(
name
,
ndir
)
if
err
!=
nil
{
d
.
lock
.
Unlock
()
return
nil
,
err
}
d
.
lock
.
Unlock
()
err
=
d
.
parent
.
closeChild
(
d
.
name
,
d
.
node
)
if
err
!=
nil
{
return
nil
,
err
}
d
.
lock
.
Lock
()
defer
d
.
lock
.
Unlock
()
return
d
.
childDir
(
name
)
}
func
(
d
*
Directory
)
Unlink
(
name
string
)
error
{
d
.
lock
.
Lock
()
defer
d
.
lock
.
Unlock
()
delete
(
d
.
childDirs
,
name
)
delete
(
d
.
files
,
name
)
err
:=
d
.
node
.
RemoveNodeLink
(
name
)
if
err
!=
nil
{
d
.
lock
.
Unlock
()
return
err
}
d
.
lock
.
Unlock
()
return
d
.
parent
.
closeChild
(
d
.
name
,
d
.
node
)
}
// RenameEntry renames the child by 'oldname' of this directory to 'newname'
func
(
d
*
Directory
)
RenameEntry
(
oldname
,
newname
string
)
error
{
d
.
Lock
()
defer
d
.
Unlock
()
// Is the child a directory?
dir
,
err
:=
d
.
childDir
(
oldname
)
if
err
==
nil
{
...
...
@@ -300,12 +297,14 @@ func (d *Directory) RenameEntry(oldname, newname string) error {
// AddChild adds the node 'nd' under this directory giving it the name 'name'
func
(
d
*
Directory
)
AddChild
(
name
string
,
nd
*
dag
.
Node
)
error
{
d
.
Lock
()
defer
d
.
Unlock
()
pbn
,
err
:=
ft
.
FromBytes
(
nd
.
Data
)
if
err
!=
nil
{
return
err
}
_
,
err
=
d
.
C
hild
(
name
)
_
,
err
=
d
.
c
hild
Unsync
(
name
)
if
err
==
nil
{
return
errors
.
New
(
"directory already has entry by that name"
)
}
...
...
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