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
86abf14b
Commit
86abf14b
authored
Aug 25, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
communicator/ssh: Trailing slash won't create destination dir
parent
09563110
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
32 deletions
+53
-32
communicator/ssh/communicator.go
communicator/ssh/communicator.go
+48
-32
packer/communicator.go
packer/communicator.go
+5
-0
No files found.
communicator/ssh/communicator.go
View file @
86abf14b
...
...
@@ -113,19 +113,30 @@ func (c *comm) Upload(path string, input io.Reader) error {
}
func
(
c
*
comm
)
UploadDir
(
dst
string
,
src
string
,
excl
[]
string
)
error
{
f
,
err
:=
os
.
Open
(
src
)
if
err
!=
nil
{
return
err
}
defer
f
.
Close
()
log
.
Printf
(
"Upload dir '%s' to '%s'"
,
src
,
dst
)
scpFunc
:=
func
(
w
io
.
Writer
,
r
*
bufio
.
Reader
)
error
{
uploadEntries
:=
func
()
error
{
f
,
err
:=
os
.
Open
(
src
)
if
err
!=
nil
{
return
err
}
defer
f
.
Close
()
entries
,
err
:=
f
.
Readdir
(
-
1
)
if
err
!=
nil
{
return
err
}
entries
,
err
:=
f
.
Readdir
(
-
1
)
if
err
!=
nil
{
return
err
}
scpFunc
:=
func
(
w
io
.
Writer
,
r
*
bufio
.
Reader
)
error
{
return
scpUploadDir
(
src
,
entries
,
w
,
r
)
return
scpUploadDir
(
src
,
entries
,
w
,
r
)
}
if
src
[
len
(
src
)
-
1
]
!=
'/'
{
log
.
Printf
(
"No trailing slash, creating the source directory name"
)
return
scpUploadDirProtocol
(
filepath
.
Base
(
src
),
w
,
r
,
uploadEntries
)
}
else
{
// Trailing slash, so only upload the contents
return
uploadEntries
()
}
}
return
c
.
scpSession
(
"scp -rvt "
+
dst
,
scpFunc
)
...
...
@@ -311,6 +322,26 @@ func scpUploadFile(dst string, src io.Reader, w io.Writer, r *bufio.Reader) erro
return
nil
}
func
scpUploadDirProtocol
(
name
string
,
w
io
.
Writer
,
r
*
bufio
.
Reader
,
f
func
()
error
)
error
{
log
.
Printf
(
"SCP: starting directory upload: %s"
,
name
)
fmt
.
Fprintln
(
w
,
"D0755 0"
,
name
)
err
:=
checkSCPStatus
(
r
)
if
err
!=
nil
{
return
err
}
if
err
:=
f
();
err
!=
nil
{
return
err
}
fmt
.
Fprintln
(
w
,
"E"
)
if
err
!=
nil
{
return
err
}
return
nil
}
func
scpUploadDir
(
root
string
,
fs
[]
os
.
FileInfo
,
w
io
.
Writer
,
r
*
bufio
.
Reader
)
error
{
for
_
,
fi
:=
range
fs
{
realPath
:=
filepath
.
Join
(
root
,
fi
.
Name
())
...
...
@@ -335,21 +366,11 @@ func scpUploadDir(root string, fs []os.FileInfo, w io.Writer, r *bufio.Reader) e
}
// 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
}
f
,
err
:=
os
.
Open
(
realPath
)
if
err
!=
nil
{
return
err
}
// Execute this in a function just so that we have easy "defer"
// available because laziness.
err
=
func
()
error
{
err
:=
scpUploadDirProtocol
(
fi
.
Name
(),
w
,
r
,
func
()
error
{
f
,
err
:=
os
.
Open
(
realPath
)
if
err
!=
nil
{
return
err
}
defer
f
.
Close
()
entries
,
err
:=
f
.
Readdir
(
-
1
)
...
...
@@ -358,12 +379,7 @@ func scpUploadDir(root string, fs []os.FileInfo, w io.Writer, r *bufio.Reader) e
}
return
scpUploadDir
(
realPath
,
entries
,
w
,
r
)
}()
if
err
!=
nil
{
return
err
}
fmt
.
Fprintln
(
w
,
"E"
)
})
if
err
!=
nil
{
return
err
}
...
...
packer/communicator.go
View file @
86abf14b
...
...
@@ -62,6 +62,11 @@ type Communicator interface {
// UploadDir uploads the contents of a directory recursively to
// the remote path. It also takes an optional slice of paths to
// ignore when uploading.
//
// The folder name of the source folder should be created unless there
// is a trailing slash on the source "/". For example: "/tmp/src" as
// the source will create a "src" directory in the destination unless
// a trailing slash is added. This is identical behavior to rsync(1).
UploadDir
(
string
,
string
,
[]
string
)
error
// Download downloads a file from the machine from the given remote path
...
...
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