Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 372DE200D1A for ; Mon, 25 Sep 2017 06:53:20 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 2F3671609E9; Mon, 25 Sep 2017 04:53:20 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4C5AC1609E6 for ; Mon, 25 Sep 2017 06:53:19 +0200 (CEST) Received: (qmail 789 invoked by uid 500); 25 Sep 2017 04:53:18 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 779 invoked by uid 99); 25 Sep 2017 04:53:18 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Sep 2017 04:53:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6BB5FF5722; Mon, 25 Sep 2017 04:53:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jaikiran@apache.org To: notifications@ant.apache.org Date: Mon, 25 Sep 2017 04:53:17 -0000 Message-Id: <631631a09b3a43a8b42fb49cfb7977b0@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] ant git commit: BZ-58589 Preserve last modified time (if asked for) for files uploaded by SFTP archived-at: Mon, 25 Sep 2017 04:53:20 -0000 Repository: ant Updated Branches: refs/heads/master a8b465489 -> 1012dd6e2 BZ-58589 Preserve last modified time (if asked for) for files uploaded by SFTP Project: http://git-wip-us.apache.org/repos/asf/ant/repo Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/7b09880b Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/7b09880b Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/7b09880b Branch: refs/heads/master Commit: 7b09880b6f1b2365e3075190d5201afcd5b17739 Parents: b912573 Author: Jaikiran Pai Authored: Sun Sep 17 18:17:48 2017 +0530 Committer: Jaikiran Pai Committed: Mon Sep 25 10:12:18 2017 +0530 ---------------------------------------------------------------------- WHATSNEW | 5 ++ .../tools/ant/taskdefs/optional/ssh/Scp.java | 4 +- .../optional/ssh/ScpToMessageBySftp.java | 69 ++++++++++++++++++-- 3 files changed, 72 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ant/blob/7b09880b/WHATSNEW ---------------------------------------------------------------------- diff --git a/WHATSNEW b/WHATSNEW index beb2cd1..f8701a9 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -30,6 +30,11 @@ Other changes: * added Orion support to ejbjar Github Pull Request #33 + * Bugzilla Report 58589 - SCP task, when configured to use SFTP + protocol, now preserves last modified timestamp on files that + it uploads, if the preserveLastModified attribute is set to + true for that task + Changes from Ant 1.9.8 TO Ant 1.9.9 =================================== http://git-wip-us.apache.org/repos/asf/ant/blob/7b09880b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java index 087a402..a8c959e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java @@ -354,7 +354,7 @@ public class Scp extends SSHBase { list, file, preserveLastModified); } else { message = new ScpToMessageBySftp(getVerbose(), session, - list, file); + list, file, preserveLastModified); } message.setLogListener(this); if (fileMode != null) { @@ -389,7 +389,7 @@ public class Scp extends SSHBase { message = new ScpToMessageBySftp(getVerbose(), session, getProject().resolveFile(fromPath), - file); + file, preserveLastModified); } message.setLogListener(this); if (fileMode != null) { http://git-wip-us.apache.org/repos/asf/ant/blob/7b09880b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java index b9a8943..65e2423 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java @@ -39,6 +39,7 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { private File localFile; private final String remotePath; private List directoryList; + private final boolean preserveLastModified; /** * Constructor for a local file to remote. @@ -52,11 +53,31 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { final Session session, final File aLocalFile, final String aRemotePath) { - this(verbose, session, aRemotePath); + this(verbose, session, aLocalFile, aRemotePath, false); + + } + + /** + * Constructor for a local file to remote. + * @param verbose if true do verbose logging + * @param session the scp session to use + * @param aLocalFile the local file + * @param aRemotePath the remote path + * @param preserveLastModified True if the last modified time needs to be preserved + * on the transferred files. False otherwise. + * @since Ant 1.9.10 + */ + public ScpToMessageBySftp(final boolean verbose, + final Session session, + final File aLocalFile, + final String aRemotePath, + final boolean preserveLastModified) { + this(verbose, session, aRemotePath, preserveLastModified); this.localFile = aLocalFile; } + /** * Constructor for a local directories to remote. * @param verbose if true do verbose logging @@ -69,23 +90,45 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { final Session session, final List aDirectoryList, final String aRemotePath) { - this(verbose, session, aRemotePath); + this(verbose, session, aDirectoryList, aRemotePath, false); + } + + /** + * Constructor for a local directories to remote. + * @param verbose if true do verbose logging + * @param session the scp session to use + * @param aDirectoryList a list of directories + * @param aRemotePath the remote path + * @param preserveLastModified True if the last modified time needs to be preserved + * on the transferred files. False otherwise. + * @since Ant 1.9.10 + */ + public ScpToMessageBySftp(final boolean verbose, + final Session session, + final List aDirectoryList, + final String aRemotePath, + final boolean preserveLastModified) { + this(verbose, session, aRemotePath, preserveLastModified); this.directoryList = aDirectoryList; } + /** * Constructor for ScpToMessage. * @param verbose if true do verbose logging * @param session the scp session to use * @param aRemotePath the remote path - * @since Ant 1.6.2 + * @param preserveLastModified True if the last modified time needs to be preserved + * on the transferred files. False otherwise. */ private ScpToMessageBySftp(final boolean verbose, final Session session, - final String aRemotePath) { + final String aRemotePath, + final boolean preserveLastModified) { super(verbose, session); this.remotePath = aRemotePath; + this.preserveLastModified = preserveLastModified; } /** @@ -266,6 +309,14 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { log("Setting file mode '" + Integer.toOctalString(getFileMode()) + "' on remote path " + transferredFileRemotePath); } channel.chmod(getFileMode(), transferredFileRemotePath); + if (getPreserveLastModified()) { + // set the last modified time (seconds since epoch) on the transferred file + final int lastModifiedTime = (int) (localFile.lastModified() / 1000L); + if (this.getVerbose()) { + log("Setting last modified time on remote path " + transferredFileRemotePath + " to " + lastModifiedTime); + } + channel.setMtime(transferredFileRemotePath, lastModifiedTime); + } } finally { if (this.getVerbose()) { final long endTime = System.currentTimeMillis(); @@ -289,4 +340,14 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { public String getRemotePath() { return remotePath; } + + /** + * Returns true if the last modified time needs to be preserved on the + * file(s) that get transferred. Returns false otherwise. + * + * @return + */ + public boolean getPreserveLastModified() { + return this.preserveLastModified; + } }