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 class TestOzoneShell {
randFile.read(dataBytes); randFile.read(dataBytes);
} }
assertEquals(dataStr, DFSUtil.bytes2String(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 @Test

View File

@ -98,11 +98,14 @@ public class GetKeyHandler extends Handler {
Path dataFilePath = Paths.get(fileName); Path dataFilePath = Paths.get(fileName);
File dataFile = new File(fileName); File dataFile = new File(fileName);
if (dataFile.exists() && dataFile.isDirectory()) {
dataFile = new File(fileName, keyName);
}
if (dataFile.exists()) { if (dataFile.exists()) {
throw new OzoneClientException(fileName + throw new OzoneClientException(
"exists. Download will overwrite an " + fileName + "exists. Download will overwrite an "
"existing file. Aborting."); + "existing file. Aborting.");
} }
OzoneVolume vol = client.getObjectStore().getVolume(volumeName); OzoneVolume vol = client.getObjectStore().getVolume(volumeName);