Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
09563110
Commit
09563110
authored
Aug 25, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
communicator/ssh: UploadDir works properly
parent
a050d344
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
58 deletions
+25
-58
communicator/ssh/communicator.go
communicator/ssh/communicator.go
+22
-34
provisioner/file/provisioner_test.go
provisioner/file/provisioner_test.go
+3
-24
No files found.
communicator/ssh/communicator.go
View file @
09563110
...
...
@@ -313,9 +313,11 @@ func scpUploadFile(dst string, src io.Reader, w io.Writer, r *bufio.Reader) erro
func
scpUploadDir
(
root
string
,
fs
[]
os
.
FileInfo
,
w
io
.
Writer
,
r
*
bufio
.
Reader
)
error
{
for
_
,
fi
:=
range
fs
{
realPath
:=
filepath
.
Join
(
root
,
fi
.
Name
())
if
!
fi
.
IsDir
()
{
// It is a regular file, just upload it
f
,
err
:=
os
.
Open
(
filepath
.
Join
(
root
,
fi
.
Name
())
)
f
,
err
:=
os
.
Open
(
realPath
)
if
err
!=
nil
{
return
err
}
...
...
@@ -328,58 +330,44 @@ func scpUploadDir(root string, fs []os.FileInfo, w io.Writer, r *bufio.Reader) e
if
err
!=
nil
{
return
err
}
}
}
return
nil
}
continue
}
func
scpWalkFn
(
cur
string
,
dst
string
,
src
string
,
w
io
.
Writer
,
r
*
bufio
.
Reader
)
filepath
.
WalkFunc
{
return
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
error
{
// It is a directory, recursively upload
log
.
Printf
(
"SCP: starting directory upload: %s"
,
fi
.
Name
())
fmt
.
Fprintln
(
w
,
"D0755 0"
,
fi
.
Name
())
err
:=
checkSCPStatus
(
r
)
if
err
!=
nil
{
return
err
}
if
path
==
cur
{
// Don't upload ourselves
return
nil
}
// Get the relative path so that we can check excludes and also
// so that we can build the full destination path
relPath
,
err
:=
filepath
.
Rel
(
src
,
path
)
f
,
err
:=
os
.
Open
(
realPath
)
if
err
!=
nil
{
return
err
}
// TODO(mitchellh): Check excludes
targetPath
:=
filepath
.
Base
(
relPath
)
if
info
.
IsDir
()
{
log
.
Printf
(
"SCP: starting directory upload: %s"
,
targetPath
)
fmt
.
Fprintln
(
w
,
"D0755 0"
,
targetPath
)
err
:=
checkSCPStatus
(
r
)
if
err
!=
nil
{
return
err
}
// Execute this in a function just so that we have easy "defer"
// available because laziness.
err
=
func
()
error
{
defer
f
.
Close
()
e
rr
=
filepath
.
Walk
(
path
,
scpWalkFn
(
path
,
dst
,
src
,
w
,
r
)
)
e
ntries
,
err
:=
f
.
Readdir
(
-
1
)
if
err
!=
nil
{
return
err
}
fmt
.
Fprintln
(
w
,
"E"
)
return
checkSCPStatus
(
r
)
return
scpUploadDir
(
realPath
,
entries
,
w
,
r
)
}()
if
err
!=
nil
{
return
err
}
// Open the file for uploading
f
,
err
:=
os
.
Open
(
path
)
fmt
.
Fprintln
(
w
,
"E"
)
if
err
!=
nil
{
return
err
}
defer
f
.
Close
()
// Upload the file like any normal SCP operation
targetPath
=
filepath
.
Base
(
relPath
)
return
scpUploadFile
(
targetPath
,
f
,
w
,
r
)
}
return
nil
}
provisioner/file/provisioner_test.go
View file @
09563110
...
...
@@ -2,7 +2,6 @@ package file
import
(
"github.com/mitchellh/packer/packer"
"io"
"io/ioutil"
"os"
"strings"
...
...
@@ -75,26 +74,6 @@ func TestProvisionerPrepare_EmptyDestination(t *testing.T) {
}
}
type
stubUploadCommunicator
struct
{
dest
string
data
[]
byte
}
func
(
suc
*
stubUploadCommunicator
)
Download
(
src
string
,
data
io
.
Writer
)
error
{
return
nil
}
func
(
suc
*
stubUploadCommunicator
)
Upload
(
dest
string
,
data
io
.
Reader
)
error
{
var
err
error
suc
.
dest
=
dest
suc
.
data
,
err
=
ioutil
.
ReadAll
(
data
)
return
err
}
func
(
suc
*
stubUploadCommunicator
)
Start
(
cmd
*
packer
.
RemoteCmd
)
error
{
return
nil
}
type
stubUi
struct
{
sayMessages
string
}
...
...
@@ -138,7 +117,7 @@ func TestProvisionerProvision_SendsFile(t *testing.T) {
}
ui
:=
&
stubUi
{}
comm
:=
&
stubUpload
Communicator
{}
comm
:=
&
packer
.
Mock
Communicator
{}
err
=
p
.
Provision
(
ui
,
comm
)
if
err
!=
nil
{
t
.
Fatalf
(
"should successfully provision: %s"
,
err
)
...
...
@@ -152,11 +131,11 @@ func TestProvisionerProvision_SendsFile(t *testing.T) {
t
.
Fatalf
(
"should print destination filename"
)
}
if
comm
.
dest
!=
"something"
{
if
comm
.
UploadPath
!=
"something"
{
t
.
Fatalf
(
"should upload to configured destination"
)
}
if
string
(
comm
.
data
)
!=
"hello"
{
if
comm
.
UploadData
!=
"hello"
{
t
.
Fatalf
(
"should upload with source file's data"
)
}
}
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