You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ay...@apache.org on 2021/03/18 19:04:58 UTC
[hadoop] branch branch-3.1 updated: HADOOP-17310. Touch command
with -c option is broken. (#2393). Contributed by Ayush Saxena.
This is an automated email from the ASF dual-hosted git repository.
ayushsaxena pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/branch-3.1 by this push:
new 8ec256d HADOOP-17310. Touch command with -c option is broken. (#2393). Contributed by Ayush Saxena.
8ec256d is described below
commit 8ec256db04cda62d006dce828a25bb0b1735c8b7
Author: Ayush Saxena <ay...@apache.org>
AuthorDate: Mon Oct 19 10:54:18 2020 +0530
HADOOP-17310. Touch command with -c option is broken. (#2393). Contributed by Ayush Saxena.
---
.../java/org/apache/hadoop/fs/shell/TouchCommands.java | 2 +-
.../test/java/org/apache/hadoop/fs/TestFsShellTouch.java | 14 ++++++++++++--
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/TouchCommands.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/TouchCommands.java
index c99777f..ba052d3 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/TouchCommands.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/TouchCommands.java
@@ -138,7 +138,7 @@ public class TouchCommands extends FsCommand {
CommandFormat cf = new CommandFormat(1, Integer.MAX_VALUE,
OPTION_USE_TIMESTAMP, OPTION_CHANGE_ONLY_ACCESS_TIME,
- OPTION_CHANGE_ONLY_MODIFICATION_TIME);
+ OPTION_CHANGE_ONLY_MODIFICATION_TIME, OPTION_DO_NOT_CREATE_FILE);
cf.parse(args);
this.changeModTime = cf.getOpt(OPTION_CHANGE_ONLY_MODIFICATION_TIME);
this.changeAccessTime = cf.getOpt(OPTION_CHANGE_ONLY_ACCESS_TIME);
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellTouch.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellTouch.java
index 2e7cb5d..62e7990 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellTouch.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellTouch.java
@@ -101,7 +101,7 @@ public class TestFsShellTouch {
{
assertThat(
"Expected successful touch on a non-existent file with -c option",
- shellRun("-touch", "-c", newFileName), is(not(0)));
+ shellRun("-touch", "-c", newFileName), is(0));
assertThat(lfs.exists(newFile), is(false));
}
@@ -140,7 +140,7 @@ public class TestFsShellTouch {
Date dateObj = parseTimestamp(strTime);
assertThat(
- "Expected successful touch with a specified modificatiom time",
+ "Expected successful touch with a specified modification time",
shellRun("-touch", "-m", "-t", strTime, newFileName), is(0));
// Verify if modification time is recorded correctly (and access time
// remains unchanged).
@@ -179,6 +179,16 @@ public class TestFsShellTouch {
assertThat("Expected failed touch with a missing timestamp",
shellRun("-touch", "-t", newFileName), is(not(0)));
}
+
+ // Verify -c option when file exists.
+ String strTime = formatTimestamp(System.currentTimeMillis());
+ Date dateObj = parseTimestamp(strTime);
+ assertThat(
+ "Expected successful touch on a non-existent file with -c option",
+ shellRun("-touch", "-c", "-t", strTime, newFileName), is(0));
+ FileStatus fileStatus = lfs.getFileStatus(newFile);
+ assertThat(fileStatus.getAccessTime(), is(dateObj.getTime()));
+ assertThat(fileStatus.getModificationTime(), is(dateObj.getTime()));
}
private String formatTimestamp(long timeInMillis) {
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org