steveloughran commented on a change in pull request #4036: URL: https://github.com/apache/hadoop/pull/4036#discussion_r832391092
########## File path: hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileUtil.java ########## @@ -706,35 +706,40 @@ public void testCreateLocalTempFile() throws IOException { public void testUnZip() throws IOException { // make sa simple zip final File simpleZip = new File(del, FILE); - OutputStream os = new FileOutputStream(simpleZip); - ZipOutputStream tos = new ZipOutputStream(os); - try { - ZipEntry ze = new ZipEntry("foo"); - byte[] data = "some-content".getBytes("UTF-8"); - ze.setSize(data.length); - tos.putNextEntry(ze); - tos.write(data); - tos.closeEntry(); - tos.flush(); - tos.finish(); - } finally { - tos.close(); - } - - // successfully unzip it into an existing dir: - FileUtil.unZip(simpleZip, tmp); - // check result: - assertTrue(new File(tmp, "foo").exists()); - assertEquals(12, new File(tmp, "foo").length()); - - final File regularFile = new File(tmp, "QuickBrownFoxJumpsOverTheLazyDog"); - regularFile.createNewFile(); - assertTrue(regularFile.exists()); - try { - FileUtil.unZip(simpleZip, regularFile); - assertTrue("An IOException expected.", false); - } catch (IOException ioe) { - // okay + try (OutputStream os = new FileOutputStream(simpleZip); + ZipArchiveOutputStream tos = new ZipArchiveOutputStream(os)) { + try { + ZipArchiveEntry ze = new ZipArchiveEntry("foo"); + ze.setUnixMode(0555); + byte[] data = "some-content".getBytes("UTF-8"); + ze.setSize(data.length); + tos.putArchiveEntry(ze); + tos.write(data); + tos.closeArchiveEntry(); + tos.flush(); + tos.finish(); + } finally { + tos.close(); Review comment: this close will be automatic. if you make the reference on L710 ``` ZipArchiveOutputStream tos = new ZipArchiveOutputStream(new FileOutputStream(simpleZip)) ``` then everything will be lined up for automatic close ########## File path: hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileUtil.java ########## @@ -706,35 +706,40 @@ public void testCreateLocalTempFile() throws IOException { public void testUnZip() throws IOException { // make sa simple zip final File simpleZip = new File(del, FILE); - OutputStream os = new FileOutputStream(simpleZip); - ZipOutputStream tos = new ZipOutputStream(os); - try { - ZipEntry ze = new ZipEntry("foo"); - byte[] data = "some-content".getBytes("UTF-8"); - ze.setSize(data.length); - tos.putNextEntry(ze); - tos.write(data); - tos.closeEntry(); - tos.flush(); - tos.finish(); - } finally { - tos.close(); - } - - // successfully unzip it into an existing dir: - FileUtil.unZip(simpleZip, tmp); - // check result: - assertTrue(new File(tmp, "foo").exists()); - assertEquals(12, new File(tmp, "foo").length()); - - final File regularFile = new File(tmp, "QuickBrownFoxJumpsOverTheLazyDog"); - regularFile.createNewFile(); - assertTrue(regularFile.exists()); - try { - FileUtil.unZip(simpleZip, regularFile); - assertTrue("An IOException expected.", false); - } catch (IOException ioe) { - // okay + try (OutputStream os = new FileOutputStream(simpleZip); + ZipArchiveOutputStream tos = new ZipArchiveOutputStream(os)) { + try { + ZipArchiveEntry ze = new ZipArchiveEntry("foo"); + ze.setUnixMode(0555); + byte[] data = "some-content".getBytes("UTF-8"); + ze.setSize(data.length); + tos.putArchiveEntry(ze); + tos.write(data); + tos.closeArchiveEntry(); + tos.flush(); + tos.finish(); + } finally { + tos.close(); + } + + // successfully unzip it into an existing dir: + FileUtil.unZip(simpleZip, tmp); + // check result: + assertTrue(new File(tmp, "foo").exists()); + assertEquals(12, new File(tmp, "foo").length()); + assertTrue("file lacks execute permissions", new File(tmp, "foo").canExecute()); + assertFalse("file has write permissions", new File(tmp, "foo").canWrite()); + assertTrue("file lacks read permissions", new File(tmp, "foo").canRead()); + + final File regularFile = new File(tmp, "QuickBrownFoxJumpsOverTheLazyDog"); + regularFile.createNewFile(); + assertTrue(regularFile.exists()); + try { Review comment: use LambdaTestUtils.intercept() here. e.g. ```java LambdaTestUtils.intercept(IOException.class, () -> FileUtil.unZip(simpleZip, regularFile)); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org