diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/ozShell/TestOzoneShell.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/ozShell/TestOzoneShell.java index a4b30f00c7..000d53039b 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/ozShell/TestOzoneShell.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/ozShell/TestOzoneShell.java @@ -705,6 +705,18 @@ public void testGetKey() throws Exception { randFile.read(dataBytes); } assertEquals(dataStr, DFSUtil.bytes2String(dataBytes)); + + tmpPath = baseDir.getAbsolutePath() + File.separatorChar + keyName; + args = new String[] {"-getKey", + url + "/" + volumeName + "/" + bucketName + "/" + keyName, "-file", + baseDir.getAbsolutePath()}; + assertEquals(0, ToolRunner.run(shell, args)); + + dataBytes = new byte[dataStr.length()]; + try (FileInputStream randFile = new FileInputStream(new File(tmpPath))) { + randFile.read(dataBytes); + } + assertEquals(dataStr, DFSUtil.bytes2String(dataBytes)); } @Test diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/GetKeyHandler.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/GetKeyHandler.java index 34620b4934..2d059e0c8c 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/GetKeyHandler.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/GetKeyHandler.java @@ -98,11 +98,14 @@ protected void execute(CommandLine cmd) Path dataFilePath = Paths.get(fileName); File dataFile = new File(fileName); + if (dataFile.exists() && dataFile.isDirectory()) { + dataFile = new File(fileName, keyName); + } if (dataFile.exists()) { - throw new OzoneClientException(fileName + - "exists. Download will overwrite an " + - "existing file. Aborting."); + throw new OzoneClientException( + fileName + "exists. Download will overwrite an " + + "existing file. Aborting."); } OzoneVolume vol = client.getObjectStore().getVolume(volumeName);