Jump to content




[QUESTION] [LUA] How can I change a file to be Read-Only?


  • You cannot reply to this topic
5 replies to this topic

#1 anonimo182

  • Members
  • 252 posts
  • LocationIn the universe

Posted 08 October 2012 - 10:58 PM

It is there any possible ways to change a file so it can only be Read-Only and it can't be modified?

Thanks :D/>

#2 faubiguy

  • Members
  • 213 posts

Posted 08 October 2012 - 11:02 PM

You could modify the functions of the fs API (during runtime) to act as if the file was read only.

For example:
readOnly = {"file/I/want/to/be/read/only" = true, "another/file" = true}
local oldFS = fs
fs.open = function(filename, mode)
 if readOnly[filename] and (mode == "w" or mode == "wb" or mode =="a" or mode == "ab") then
  return nil
 else
  return oldFS.open(filename, mode)
 end
end


#3 anonimo182

  • Members
  • 252 posts
  • LocationIn the universe

Posted 08 October 2012 - 11:19 PM

so I need to paste that in my file?

#4 faubiguy

  • Members
  • 213 posts

Posted 08 October 2012 - 11:23 PM

You need to write a version of every fs function that is affected by read-only files (open, isReadOnly, copy, and delete)

#5 anonimo182

  • Members
  • 252 posts
  • LocationIn the universe

Posted 08 October 2012 - 11:28 PM

Where I write them?

#6 faubiguy

  • Members
  • 213 posts

Posted 08 October 2012 - 11:49 PM

The files will be made read-only when the code runs, so if you want them to be read only all the time, you should put it in your startup file.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users