How to create a file lock on any txt, php, css or

2019-09-10 09:26发布

At the office, we're a few developers working on the same projets all the time. Sometimes, we're modifying a file (PHP or CSS or JS or ...) and we don't know if someone else is modifying the same file at the same time. Of course we're using GIT for larger projects but when it's a small project we just do it on our local server.

I was thus wondering if there was some kind of lock, similar to what we have with an Openoffice document where when the file is open on a computer and another computer tries to open the same file, it gets a warning message saying "Computer X has the document opened. Do you want to open the file in read-only or open a local copy ?".

I guess this is an application thing that creates the lock when it opens a file, and not a Ubuntu thing ? We're used to working with Kate so maybe there's another text editor that could provide us with lock ? Or could we write some kind of persistent script that would check whenever we open a file and create a lock (and destroy the lock upon closing the file) ?

Thanks in advance for your thoughts on that matter! :o)

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-09-10 09:46

There is a command called chattr on many linux systems (change attribute) and you can make a file immutable using the i flag.

chattr +i file.txt

Now no one can delete or write to this file until

chattr -i file.txt

Maybe this is something you are looking for?

查看更多
Melony?
3楼-- · 2019-09-10 10:01

You should always use a version control system (like git), especially when there are more than one developer. Come on, it takes a few seconds to create a git repo.

For the most efficient work, you should also set up a separate dev environmet (apache virtualhosts and MySQL databases) for every programmer. I would not like somebody else's var_dump'ed output on my screen.

查看更多
登录 后发表回答