-1

I have a poorly designed build script that always overwrites files that it shouldn't; if I edit these files and then run the script, it overwrites their content and, thus, the build fails.

How can I "lock" these files so that the overwrite fails?

I've tried opening them in editors (vi(m), gedit) but overwrite works regardless?

3
  • 3
    Modifying the files permissions is the obvious way. However, if why not modify the script so that it does not overwrite the files? If that is a shell script, you could add set -C to it. Commented Nov 27, 2020 at 19:00
  • Note: set -C only prevents overwriting by redirection (>). It would not prevent gcc a.c -o a from overwriting a. And the script can overwrite files by mv x a, so that is another thing. All in all, better to give us more details. Commented Nov 27, 2020 at 19:27
  • Read man - a chmod and use the +i (immutable) flag. Commented Nov 27, 2020 at 23:19

1 Answer 1

1

Fixing your poorly designed script seems like the best option. Any other thing may be too intrusive.

However, in some situations it may not be possible. If the script is very big and complicated it may be too much work.

An intermediate solution would be to have a user with the lowest privileges, and have the build script switch to that user in the beginning. The file permissions of the system will do the rest...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.