Skip to content
Browse files

ssh publish: copy then move to prevent rejects

  • Loading branch information...
1 parent 45700be commit 2970f276f4b9449e80b60f8ccbf91b1f91e53d24 Felix Lange committed Aug 30, 2010
Showing with 12 additions and 3 deletions.
  1. +8 −2 src/tep_ssh.erl
  2. +4 −1 src/tetrapak_repo_ssh.erl
View
10 src/tep_ssh.erl
@@ -9,7 +9,7 @@
-module(tep_ssh).
-export([login/3, close/1]).
--export([run/2, ls/2, scp/3, file_info/2, is_dir/2]).
+-export([run/2, ls/2, scp/3, mv/3, file_info/2, is_dir/2]).
%% internal
-export([init/1]).
@@ -45,6 +45,8 @@ ls(Session, RemoteDir) ->
call(Session, sftp, {ls, RemoteDir}).
scp(Session, Local, Remote) ->
call(Session, sftp, {scp, Local, Remote}).
+mv(Session, From, To) ->
+ call(Session, sftp, {mv, From, To}).
file_info(Session, Path) ->
call(Session, sftp, {file_info, Path}).
@@ -109,9 +111,13 @@ do_sftp_cmd(Conn, {scp, Local, Remote}) ->
end;
do_sftp_cmd(Conn, {file_info, Path}) ->
- tep_log:debug("ssh: file_info ~p", [Path]),
+ tep_log:debug("ssh: sftp file_info ~p", [Path]),
ssh_sftp:read_file_info(Conn, Path, 1000);
+do_sftp_cmd(Conn, {mv, From, To}) ->
+ tep_log:debug("ssh: sftp mv ~p -> ~p", [From, To]),
+ ssh_sftp:rename(Conn, From, To);
+
do_sftp_cmd(_Conn, Cmd) ->
tep_log:warn("ssh: unknown sftp command: ~p", [Cmd]),
{error, bad_sftp_cmd}.
View
5 src/tetrapak_repo_ssh.erl
@@ -27,8 +27,11 @@ publish(PackageFile, Repo = #tep_repository{options = Props}) ->
end,
{ok, SSH} = tep_ssh:login(Host, Port, UserCfg),
Target = filename:join(Path, filename:basename(PackageFile)),
+ TargetTmp = Target ++ ".upload-tmp",
case tep_ssh:is_dir(SSH,Path) of
- true -> tep_ssh:scp(SSH, PackageFile, Target);
+ true ->
+ tep_ssh:scp(SSH, PackageFile, TargetTmp),
+ tep_ssh:mv(SSH, TargetTmp, Target);
false -> tep_log:warn("remote repository path ~s is not a directory", [Path])
end,
tep_ssh:close(SSH),

0 comments on commit 2970f27

Please sign in to comment.
Something went wrong with that request. Please try again.