Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Levin Zimmermann
go-fuse
Commits
03784884
Commit
03784884
authored
May 14, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement fuse.CopyFile to copy between FileSystems generically.
Use it in UnionFs.
parent
df652252
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
52 deletions
+131
-52
fuse/Makefile
fuse/Makefile
+18
-15
fuse/copy.go
fuse/copy.go
+56
-0
fuse/copy_test.go
fuse/copy_test.go
+48
-0
unionfs/unionfs.go
unionfs/unionfs.go
+9
-37
No files found.
fuse/Makefile
View file @
03784884
...
...
@@ -3,32 +3,35 @@ include $(GOROOT)/src/Make.inc
TARG
=
github.com/hanwen/go-fuse/fuse
GOFILES
=
api.go
\
misc.go
\
request.go
\
fuse.go
\
direntry.go
\
mount.go
\
types.go
\
pathfilesystem.go
\
GOFILES
=
\
api.go
\
bufferpool.go
\
copy.go
\
default.go
\
direntry.go
\
files.go
\
fuse.go
\
latencymap.go
\
lockingfs.go
\
loggingfs.go
\
loopback.go
\
misc.go
\
mount.go
\
opcode.go
\
pathdebug.go
\
pathfilesystem.go
\
pathops.go
\
request.go
\
timingfs.go
\
timingrawfs.go
\
types.go
\
version.gen.go
\
xattr.go
\
pathdebug.go
\
opcode.go
\
pathops.go
\
latencymap.go
\
loggingfs.go
\
version.gen.go
include
$(GOROOT)/src/Make.pkg
version.gen.go
:
echo
"package fuse"
>
$@
git log
-n1
--pretty
=
format:
'const version = "%h (%cd)"'
--date
=
iso
>>
$@
include
$(GOROOT)/src/Make.pkg
fuse/copy.go
0 → 100644
View file @
03784884
package
fuse
import
(
"os"
)
func
CopyFile
(
srcFs
,
destFs
FileSystem
,
srcFile
,
destFile
string
)
Status
{
src
,
code
:=
srcFs
.
Open
(
srcFile
,
uint32
(
os
.
O_RDONLY
))
if
!
code
.
Ok
()
{
return
code
}
defer
src
.
Release
()
defer
src
.
Flush
()
attr
,
code
:=
srcFs
.
GetAttr
(
srcFile
)
if
!
code
.
Ok
()
{
return
code
}
w
:=
WriteIn
{
Flags
:
uint32
(
os
.
O_WRONLY
|
os
.
O_CREATE
|
os
.
O_TRUNC
),
}
dst
,
code
:=
destFs
.
Create
(
destFile
,
w
.
Flags
,
attr
.
Mode
)
if
!
code
.
Ok
()
{
return
code
}
defer
dst
.
Release
()
defer
dst
.
Flush
()
bp
:=
NewBufferPool
()
r
:=
ReadIn
{
Size
:
128
*
(
1
<<
10
),
}
for
{
data
,
code
:=
src
.
Read
(
&
r
,
bp
)
if
!
code
.
Ok
()
{
return
code
}
if
len
(
data
)
==
0
{
break
;
}
n
,
code
:=
dst
.
Write
(
&
w
,
data
)
if
!
code
.
Ok
()
{
return
code
}
if
int
(
n
)
<
len
(
data
)
{
return
EIO
}
if
len
(
data
)
<
int
(
r
.
Size
)
{
break
;
}
r
.
Offset
+=
uint64
(
len
(
data
))
w
.
Offset
+=
uint64
(
len
(
data
))
bp
.
FreeBuffer
(
data
)
}
return
OK
}
fuse/copy_test.go
0 → 100644
View file @
03784884
package
fuse
import
(
"testing"
"io/ioutil"
)
func
TestCopyFile
(
t
*
testing
.
T
)
{
d1
:=
MakeTempDir
()
d2
:=
MakeTempDir
()
fs1
:=
NewLoopbackFileSystem
(
d1
)
fs2
:=
NewLoopbackFileSystem
(
d2
)
content1
:=
"blabla"
err
:=
ioutil
.
WriteFile
(
d1
+
"/file"
,
[]
byte
(
content1
),
0644
)
CheckSuccess
(
err
)
code
:=
CopyFile
(
fs1
,
fs2
,
"file"
,
"file"
)
if
!
code
.
Ok
()
{
t
.
Fatal
(
"Unexpected ret code"
,
code
)
}
data
,
err
:=
ioutil
.
ReadFile
(
d2
+
"/file"
)
if
content1
!=
string
(
data
)
{
t
.
Fatal
(
"Unexpected content"
,
string
(
data
))
}
content2
:=
"foobar"
err
=
ioutil
.
WriteFile
(
d2
+
"/file"
,
[]
byte
(
content2
),
0644
)
CheckSuccess
(
err
)
// Copy back: should overwrite.
code
=
CopyFile
(
fs2
,
fs1
,
"file"
,
"file"
)
if
!
code
.
Ok
()
{
t
.
Fatal
(
"Unexpected ret code"
,
code
)
}
data
,
err
=
ioutil
.
ReadFile
(
d1
+
"/file"
)
if
content2
!=
string
(
data
)
{
t
.
Fatal
(
"Unexpected content"
,
string
(
data
))
}
}
unionfs/unionfs.go
View file @
03784884
...
...
@@ -4,7 +4,6 @@ import (
"crypto/md5"
"fmt"
"github.com/hanwen/go-fuse/fuse"
"io"
"io/ioutil"
"log"
"os"
...
...
@@ -229,48 +228,21 @@ func (me *UnionFs) putDeletion(name string) fuse.Status {
////////////////
// Promotion.
// From the golang blog.
func
CopyFile
(
dstName
,
srcName
string
)
(
written
int64
,
err
os
.
Error
)
{
src
,
err
:=
os
.
Open
(
srcName
)
if
err
!=
nil
{
return
}
defer
src
.
Close
()
dir
,
_
:=
filepath
.
Split
(
dstName
)
fi
,
err
:=
os
.
Stat
(
dir
)
if
fi
!=
nil
&&
!
fi
.
IsDirectory
()
{
return
0
,
os
.
NewError
(
"Destination is not a directory."
)
}
if
err
!=
nil
{
return
0
,
err
}
dst
,
err
:=
os
.
Create
(
dstName
)
if
err
!=
nil
{
return
}
defer
dst
.
Close
()
return
io
.
Copy
(
dst
,
src
)
}
func
(
me
*
UnionFs
)
Promote
(
name
string
,
srcResult
branchResult
)
fuse
.
Status
{
writable
:=
me
.
branches
[
0
]
sourceFs
:=
me
.
branches
[
srcResult
.
branch
]
// Promote directories.
me
.
promoteDirsTo
(
name
)
_
,
err
:=
CopyFile
(
writable
.
GetPath
(
name
),
sourceFs
.
GetPath
(
name
)
)
r
:=
me
.
getBranch
(
name
)
r
.
branch
=
0
me
.
branchCache
.
Set
(
name
,
r
)
if
err
!=
nil
{
log
.
Println
(
"promote error: "
,
name
,
err
.
String
())
return
fuse
.
EPERM
code
:=
fuse
.
CopyFile
(
sourceFs
,
writable
,
name
,
name
)
if
!
code
.
Ok
()
{
me
.
branchCache
.
GetFresh
(
name
)
return
code
}
else
{
r
:=
me
.
getBranch
(
name
)
r
.
branch
=
0
me
.
branchCache
.
Set
(
name
,
r
)
}
return
fuse
.
OK
...
...
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