HDDS-210. Make "-file" argument optional for ozone getKey command. Contributed by Lokesh Jain.

This commit is contained in:
Xiaoyu Yao 2018-07-13 11:44:24 -07:00
parent 88625f5cd9
commit 103f2eeb57
2 changed files with 18 additions and 3 deletions

View File

@ -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

View File

@ -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);