java执行linux语句带权限_linux-Java文件在JVM中可设置为可写的,具有权限

我使用Gitlab CI和image从源代码构建apacheflinkjava:8u111 jdk,并发现对文件权限的 test失败,因为不尊重文件权限。

其中一个单元 test类似于:

@Test

public void testDeleteDirectory() throws Exception {

// deleting a non-existent file should not cause an error

File doesNotExist = new File(tmp.newFolder(), "abc");

FileUtils.deleteDirectory(doesNotExist);

// deleting a write protected file should throw an error

File cannotDeleteParent = tmp.newFolder();

File cannotDeleteChild = new File(cannotDeleteParent, "child");

try {

assumeTrue(cannotDeleteChild.createNewFile());

assumeTrue(cannotDeleteParent.setWritable(false));

assumeTrue(cannotDeleteChild.setWritable(false));

FileUtils.deleteDirectory(cannotDeleteParent);

fail("this should fail with an exception");

}

catch (AccessDeniedException ignored) {

// this is expected

}

finally {

//noinspection ResultOfMethodCallIgnored

cannotDeleteParent.setWritable(true);

//noinspection ResultOfMethodCallIgnored

cannotDeleteChild.setWritable(true);

}

}

试验结果为:

testDeleteDirectory(org.apache.flink.util.FileUtilsTest) Time elapsed: 0.022 sec <<< FAILURE!

java.lang.AssertionError: this should fail with an exception

at org.junit.Assert.fail(Assert.java:88)

at org.apache.flink.util.FileUtilsTest.testDeleteDirectory(FileUtilsTest.java:129)

当我深入研究代码时,我在java.io.File文件:

在某些平台上,可以使用特殊权限启动Java虚拟机,允许它修改不允许写操作的文件。

所以我怀疑是CI环境出了问题。如何进一步调试该问题?谢谢!

环境:

docker图像:java:8u111 jdk

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值