Questions tagged [filelock]

File locks are locks held by an application, preventing interference from other processes. Locks may be advisory (may be ignored by others), or mandatory, enforced by the operating system, depending on implementation.

File locks are locks held by an application, preventing interference from other processes. Locks may be advisory (may be ignored by others), or mandatory, enforced by the operating system, depending on implementation.

190 questions
2
votes
0 answers

"Simulate" an external program reading/holding on to a file, preventing File#delete()

I am currently looking into an issue with Logback where the Compressor class is unable to delete a file if I open it in the log file reader glogg. This situation only happens with that program, should I open the file in Notepad.exe no issues arise,…
oligofren
  • 20,744
  • 16
  • 93
  • 180
2
votes
0 answers

Open command does (or does not) lock the file?

Obversation 1: On Windows 10, I open two command windows ("cmd"). On both, I start python for an interactive session. In both, I open my test file via f = open("test.xlsx", "a+"). No error message in the second command window, despite the file being…
R-obert
  • 553
  • 4
  • 13
2
votes
1 answer

boost::interprocess::file_lock erroneous behavior when used with std::ostream

I am trying to use file_lock for restricting multiple instances of the same program running at the same time (Implementing something mentioned in this answer). I am using 1.66 version of boost on Linux. Before locking the file, I make sure that file…
abhiarora
  • 9,743
  • 5
  • 32
  • 57
2
votes
1 answer

What's the purpose of waiting in FileChannel.lock if OverlappingFileLockException is thrown anyway?

FileChannel.lock allows to create file lock in Java (I use the approach from How can I lock a file using java (if possible) with FileOutputStream in order to avoid NonWritableChannelException): FileOutputStream out = new FileOutputStream(file); try…
Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
2
votes
1 answer

File Locking in java

I have a list of files in a folder, I want to lock a specific file(user send me the name of the file to be locked), which i am doing as below: try { File file = new File("filename"); FileChannel channel = new RandomAccessFile(file,…
Sidharth
  • 1,402
  • 2
  • 16
  • 37
2
votes
0 answers

Cross-platform cooperative file locking through link/folder creation?

I would like to implement a cooperative file locking mechanism in Python, that would also work on remote partitions (e.g. NFS), with a simple code (I want to avoid using a third-party module, because I want some specific open-source code to not have…
Eric O. Lebigot
  • 91,433
  • 48
  • 218
  • 260
2
votes
2 answers

Check if a file that's not locked is open

Some programs (image programs such as Paint, text editors such as notepad and Wordpad,and others) open files, load the contents into memory, then release the file lock. Is there a way to tell if a program is using that file even though it's not…
JohnRL
  • 21
  • 3
2
votes
1 answer

can't acquire a lock on a file

FileLocker_wo.h #include namespace Utils { namespace FileLocker { bool lock_file(std::string aFileName, int& aFileDescriptor); bool unlock_file(int& aFileDescriptor); bool…
Naren
  • 139
  • 1
  • 17
2
votes
1 answer

what happens with FileLock on JVM crash?

I'm just wondering what happens with a lock from FileLock, if a JVM crashes hard or it gets a SIGKILL. Nothing in the FileLock doc is specified about it, so I assume it is released. Just want to make sure, though... Thx
cecemel
  • 616
  • 2
  • 7
  • 22
2
votes
1 answer

Golang flock filelocking throwing panic: runtime error: invalid memory address or nil pointer dereference

I have a go program that modifies my configuration file. I am trying to create a filelock from within the main() function, but it is throwing a panic: runtime error: invalid memory address or nil pointer dereference error. Without the lock, the…
nohup
  • 3,105
  • 3
  • 27
  • 52
2
votes
1 answer

FileChannel.tryLock sometimes throws AccessDeniedException

I've written a small method that is meant to tell me if another instance of the application is already running. I am aware that there are many ways to find out if another instance is running, but I chose this one. I am creating an empty file and…
Klitos Kyriacou
  • 10,634
  • 2
  • 38
  • 70
2
votes
1 answer

File locks and transactions

I'm writing a very simple pipeline for processing uploaded files and I've opted to keep the state of the pipeline on the file system instead of a database. The pipeline itself is very simple because files are processed in temporary locations and…
David K.
  • 6,153
  • 10
  • 47
  • 78
2
votes
2 answers

How to Copy a file without locking it?

I have a large log file located on a network drive that is being constantly written to. How can I copy it through code without locking it? Try Microsoft.VisualBasic.FileSystem.FileCopy("sourcefile", "destinationfile") Catch ex As…
George
  • 2,165
  • 2
  • 22
  • 34
2
votes
1 answer

Ruby: How to acquire file lock for writing?

What I want to achieve is this: if some other process is holding the lock, quit otherwise acquire the lock for writing The Ruby code I am trying to modify is. File.open(filename, "wb") { |inf| if inf.flock(File::LOCK_EX|File::LOCK_NB) == 0 …
user180574
  • 5,681
  • 13
  • 53
  • 94
2
votes
1 answer

How do I determine if an H2 database file lock exists?

For reasons that I will not explain (because people will direct their responses at the other topic, instead of my problem at hand), I need to know how to determine whether or not my H2 database is locked. Using Java code, how do I determine whether…
Ryan
  • 511
  • 1
  • 8
  • 18