When I run:
Files.delete(Paths.get(filepath));
I get:
java.nio.file.FileSystemException: /tmp/some-file: OperationNotPermitted
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:91) ~[?:1.8.0_102]
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) ~[?:1.8.0_102]
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107) ~[?:1.8.0_102]
at sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:244) ~[?:1.8.0_102]
at sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:103) ~[?:1.8.0_102]
at java.nio.file.Files.delete(Files.java:1126) ~[?:1.8.0_102]
...
The file has permissions:
-rw-rw-rw- some-user-1 some-group
and lsattr
shows that it's not immutable:
-------------e-
The Java code is turned into script that does some stuff and ultimately runs java
on SpringLauncher:
sudo -u some-user-2 the-script
some-user-2
is not in some-group, but the file has user write permissions and /tmp/
has 777 permissions, so why am I not able to delete it in Java?
When I change the user (chown /tmp/some-file some-user-2
), I am able to delete it with the above Java code. This also confuses me.