# Lock file while copying

**URL:** <https://www.ruby-forum.com/t/lock-file-while-copying/193804>\
**Category:** Ruby\
**Created:** [August 24, 2010, 5:50pm UTC](https://www.ruby-forum.com/t/lock-file-while-copying/193804 "2010-08-24T17:50:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [August 24, 2010, 5:50pm UTC](https://www.ruby-forum.com/t/lock-file-while-copying/193804/1 "2010-08-24T17:50:42Z")

</div>

Hi,

Is it possible during File.copy to lock that file from any other  
process?

Thanks

Aidy

---

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [August 26, 2010, 3:59pm UTC](https://www.ruby-forum.com/t/lock-file-while-copying/193804/2 "2010-08-26T15:59:48Z")

</div>

aidy wrote:

> Is it possible during File.copy to lock that file from any other  
> process?

Not normally - unless your operating system supports Mandatory File  
Locking and has it enabled.

Most OSes use Advisory File Locking, which means that a lock can be  
made, but it’s up to the other process to try to lock the file itself  
before updating it. It could simply not bother and go ahead with the  
update anyway.
