file-locking

Forcing file deletion on Windows from Java

Is there a programatic way from java to force a file deletion on windows even if the file is locked by some process? I cannot kill the process that locks the file. ...

Lock / Prevent edit of source files on Linux using C++

How can I programmatically lock/unlock, or otherwise prevent/enable editing, a source file on Linux using C++. I want to be able to lock source file so that if I open it in an editor it will not allow me to save back to the same source file. I am thinking of maybe changing the permissions to read-only (and change it back to read-write ...

How can I unlock a file that is locked by a process in .NET

I want my application to clean all the temp files it used, the problem is that not all the temp files are under my control, so I just want to "brutally" unlock them in order to delete them, something similar to what the unlocker does, but programatically. ...

How do I find out which process is locking a file using .NET?

I've seen several of answers about using Handle or Process Monitor, but I would like to be able to find out in my own code (C#) which process is locking a file. I have a nasty feeling that I'm going to have to spelunk around in the win32 API, but if anyone has already done this and can put me on the right track, I'd really appreciate...

Unlock a file with unlocker from a WinForms App?

I am trying to unlock a file from a C# program, using unlocker. In my UI, I put a button to unlock the file the app couldn't delete. When the user pushes the button, I want unlocker (the famous app) to be opened. I have read about in the Unlocker web, and there is some explanations about the commandline to use but nothing works. I wri...

Locking a file in Python

Hello, I need to lock a file for writing in Python. It will be accessed from multiple Python processes at once. I have found some solutions online, but most fail for my purposes as they are often only Unix based or Windows based. Any help would be appreciated. Thanks. ...

How to let humans and programs access the same file without stepping on each others' toes.

Suppose I have a file, urls.txt, that contains a list of URLs I'm monitoring. My monitoring script edits that file occasionally, say, to indicate whether each URL is reachable. I'd like to also manually edit that file, to add to or change the list of URLs. How can I allow that such that I don't have to think about it when manually edi...

FileSystemWatcher.WaitForChanged returns, but there is still a lock on the file

I have a program that send a document to a pdf printer driver and that driver prints to a particular directory. After the print I want to attach the pdf to an e-mail (MailMessage) and send it off. Right now, I send the document to the printer (wich spawns a new process) and then call a FileSystemWatcher.WaitForChanged(WaitForChangedRes...

TFS won't allow folder rename, claims that there are locks

In visual studio 2008, I want to rename a folder due to a typo in the name. I rename it in the solution structure. The folder and .CSProj files are now checked out, and I check in. TFS comes back with "Microsoft Visual studio cannot perform the source control operation at this time because some of the files involved in the operation are...

File.Copy locks source file after completion.

We are trying to copy a file from a server, down to a local machine in a .NET 2.0 application (C#), but keep having the source file unnecessarily locked. We suspect it is something configured on the file server that is causing this behaviour, but are not sure what ... can you help? After the file copy operation, the file server (Windows...

Lock a file while writing it on the disk

I have two independant threads F1 and F2 (to be precise, two instances of java.util.concurrent.FutureTask) that are running in parallel. F1 do some processing, and then copy the result in a XML file. Then, it repeats these steps until it has nothing to do (many XML files are created). F2 looks in the F1 output directory, and take one fi...

Log File Monitor

Is is possible to open a text file and read the contents while another application is updating the file, in such a way that it does not cause a lock conflict? I need to monitor a log file from one application which is updated by another application each time an event occurs. I do check if the file is in use before I try to read it, bu...

Extra Process file locks

I have a .NET system where I need to allow files to be locked and unlocked across process boundaries. The model I plan to use is this: User generate a lock token Uses Locks a file with token and refreshes token repeat at #2 as needed Uses unlocks all files by releasing token If uses fails to refresh token in some time-frame, #4 happens...

How do I can linux flock command to prevent another root process deleting a file?

Hello there, I would like to prevent one of my root process from deleting a certaing file. So I came across the flock command, it seems to fit my need, but I didnt get its sintax. If I only indicate a shared lock, it doesnt work: flock -s "./file.xml" If I add a timeout parameter, it still doesnt work flock -s -w5 "./file.xml" It ...

What happens in 'assembly purgatory'?

When a .NET assembly is deployed to the GAC and the destination file is locked, Windows holds it in what I can best guess is some sort of 'assembly purgatory' - c:\windows\assembly\temp. Using Process Explorer these can easily be seen when searching for the suspect DLL: As soon as I end the process locking the file (in this case OWST...

Correctly destroying named System V semaphores

I'm using named System V semaphores to lock a file across all my apps on OSX and linux. Not prettiest of APIs by any definition. It seems to work, but I can't quite figure out how to properly destroy the semaphore after everybody is done with it. General logic is like this: Creating: [1] Thread or process tries to open a semaphore se...

Prevent the access from copying a file when other resources are using it.

In my application, i have one exe file that will do some conversion on my videofiles in a directory, and also i have used cute ftp to transfer the files present in the directory to another server. CUTE FTP is configured to be run on every mins. When 25% of job is over for a video file, CUTEFTP is transferred that file to other server. ...

Locking and Updating a File Accordingly

Note: I have read other posts on how to lock and unlock a file. I didn't find anything special that I wasn't aware of. So I am gonna put my scenario here so that someone can give some suggestions out. In my experience, FileChannel.lock doesn't guarantee the situation of locking and unlocking of a File when different Objects from multipl...

File r/w locking and unlink

Hello, I have following problem. I want to create a file system based session storage where each session data is stored in simple file named with session ids. I want following API: write(sid,data,timeout), read(sid,data,timeout), remove(sid) where sid==file name, Also I want to have some kind of GC that may remove all timed-out session...

File Unlocking and Deleting as single operation

Hello, Please note this is not duplicate of http://stackoverflow.com/questions/1910624/file-r-w-locking-and-unlink. (The difference - platform. Operations of files like locking and deletion have totally different semantics, thus the sultion would be different). I have following problem. I want to create a file system based session stor...