This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
natedogith1's profile picture

[Question][Java] Folders that can't be deleted

Started by natedogith1, 18 March 2012 - 03:13 AM
natedogith1 #1
Posted 18 March 2012 - 04:13 AM
I'm looking for a way to make a folder delete-safe. If I set every permission, excluding "List folder / read data" on every profile to deny, I can still delete the folder. I'm looking for a way to do this because I want to create a symbolic link to C:\ but I don't want to accidentally delete my hard drive. btw: it seems that delete will delete go through the sub-directories and delete those, not just the directory it was called on.
Espen #2
Posted 18 March 2012 - 11:59 AM
Haven't tried it yet, but all folders within /rom should be safe from modification (from within CC).
Just tried it myself with a symbolic link. You definitely can't delete or modify anything in the linked folder, as long as it's in /rom.
The downside though is that everything in /rom is accessible by ALL CC computers.

It should be possible to prevent folders from being modified without having to place them in /rom though.
Haven't tried that one yet, but it should theoretically be possible by setting the correct user rights, etc.
Edited on 18 March 2012 - 11:08 AM
natedogith1 #3
Posted 18 March 2012 - 12:01 PM
yeah, but I'm putting a directory symbolic link in the computer's folder
Espen #4
Posted 18 March 2012 - 12:26 PM
yeah, but I'm putting a directory symbolic link in the computer's folder
Yes I know, I tried it with a symbolic link myself. See my post again.:D/>/>
Btw. in the meantime I've tried putting it outside the /rom folder, inside one specific CC computer, and setting user rights.
I'm on Win7 and this is what I've found out through trial and error (write-protection was on for all of the following):
If you only allow reading rights, then you can't open the file from within CC with the edit program or delete it, but you can still rename it.
If you only disallow writing rights, then you can open it within edit, but you can't save changes. Renaming is still possible though.

So changing user rights is not an iron-clad method and is either too restrictive or too permissive.
And besides, I have no idea how this behaves in SMP, i.e. in which user-context clients access your game.^^
Liraal #5
Posted 18 March 2012 - 12:29 PM
i have an idea: make a quick modification to ROM and add your folder to the read-only list. Checking that now.
That certainly is not easy, the simplest way i can think of is to modify fs.open and io.open to allow only "r" mode with given files.
natedogith1 #6
Posted 18 March 2012 - 12:37 PM
yeah, but I'm putting a directory symbolic link in the computer's folder
Yes I know, I tried it with a symbolic link myself. See my post again. :D/>/>
Btw. in the meantime I've tried putting it outside the /rom folder, inside one specific CC computer, and setting user rights.
I'm on Win7 and this is what I've found out through trial and error (write-protection was on for all of the following):
If you only allow reading rights, then you can't open the file from within CC with the edit program or delete it, but you can still rename it.
If you only disallow writing rights, then you can open it within edit, but you can't save changes. Renaming is still possible though.

So changing user rights is not an iron-clad method and is either too restrictive or too permissive.
And besides, I have no idea how this behaves in SMP, i.e. in which user-context clients access your game.^^

from my tests, the only way I can prevent it from getting deleted is by disabling the "List folder / read data" permission, and that seems to only work because computer craft can't traverse the file tree.