1

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.

Lycus
  • 410
  • 1
  • 6
  • 15
  • Can you `rm` the file from the command line? If not, then the problem is nothing to do with Java. – user253751 Oct 05 '16 at 03:00
  • 3
    Also the likely reason is that /tmp has the sticky permission bit set. – user253751 Oct 05 '16 at 03:00
  • When I run `sudo -u some-user-2 rm /tmp/some-file`, it tells me "Operation not permitted." So yeah, it seems like Java is not the culprit – Lycus Oct 05 '16 at 03:04
  • I did the `rm`, just copied it wrong. Will edit. It looks like the /tmp/ sticky bit is indeed set (I see a "t" at the end of the bits). – Lycus Oct 05 '16 at 03:07
  • Just changed the sticky bit with `sudo chmod -t /tmp`. Then ran `rm`. It worked after that, so it seems like the sticky bit was the issue. You learn something new everyday – Lycus Oct 05 '16 at 03:09
  • 1
    http://unix.stackexchange.com/questions/79395/how-does-the-sticky-bit-work for more information – Erwin Bolwidt Oct 05 '16 at 03:19
  • @Lycus Of course, with that bit unset anyone can delete anyone else's temporary files... – user253751 Oct 05 '16 at 03:30
  • 1
    To delete a file from a directory in Unix-like systems, you also need write access to the directory itself, not only to the file. – mtj Oct 05 '16 at 05:46

0 Answers0