473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Drop folder and race conditions

I have a need to implement a drop folder upload mechanism for secure uploading
of files to a server. At first glance this appears that it would be an easy
application to write. Then I begin to think about the race conditions that
exist between the process that will wake up to upload the files and the fact
that the user can add additional files to the drop folder at any point in time.
I would like to clear out files/folders after they have been processed but it is
possible that while the background process was uploading files, the user added
additional files/folders to the drop folder that make the deletion of folders
impossible. This project has become significantly more complex than it appeared
at first. Anyone out there have any "sage" advice on how to tackle this beast?

Thanks in advance for any pointers.

Regards,
Larry Bates
Oct 9 '07 #1
1 1517
On Tue, 09 Oct 2007 07:05:57 -0500, Larry Bates wrote:
I have a need to implement a drop folder upload mechanism for secure
uploading of files to a server. At first glance this appears that it
would be an easy application to write. Then I begin to think about the
race conditions that exist between the process that will wake up to
upload the files and the fact that the user can add additional files to
the drop folder at any point in time. I would like to clear out
files/folders after they have been processed but it is possible that
while the background process was uploading files, the user added
additional files/folders to the drop folder that make the deletion of
folders impossible. This project has become significantly more complex
than it appeared at first. Anyone out there have any "sage" advice on
how to tackle this beast?

Off the top of my head...

Recursively copy the contents of each folder to the server, deepest
first, deleting each file as it's copied. Then delete the folder as soon
as you've emptied it (but naturally not the top-level drop folder). If it
happens to *not* be empty (because the user has added additional files to
it), just catch the error and ignore it. In another few minutes, you'll
try again, copying the newly added files and then delete the folder.

Because each file is being deleted as soon as it is copied, you'll won't
build up an ever-increasing collection of files. At worst, you may have a
collection of folders -- but unless you're fighting a hostile process
that can add folders quicker than you can delete them, you'll eventually
win.

Maybe you need a heuristic that says "if the number of 'directory not
empty' errors keeps increasing, assume we're dealing with a hostile
process and take extra steps". Say, lock the drop folder for five minutes
while you flush it.

Another possibility is that before you start copying from the folders,
you change their permissions to prohibit the user adding extra files into
them. That way, nothing can be added to them once you start copying, and
you can be sure that you can delete them once empty.
--
Steven
Oct 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: GIMME | last post by:
One of my coworkers insists that one should never use static methods because race conditions exist. Thinking along the lines that all variable assignments are assignments to static variables. ...
18
by: Urs Vogel | last post by:
Hi I wrote an application server (a remoting sinlgeton), where processes must be stopped in very rare cases, done thru a Thread.Abort(). Occasionally, and only after a Thread.Abort(), this...
6
by: Ernesto | last post by:
I couldn't find this with a search, but isn't there a way to overwrite a previous folder (or at least not perform osmkdir( ) if your program detects it already exists). Thanks !
2
by: manuelg | last post by:
Here is a code fragment, where I am trying to copy a file, avoiding overwrites and race conditions. The filename gets a '02','03','04' etc appended to the end if a file with that name already...
4
by: SStory | last post by:
I want to drag a message from Outlook to a richtextbox on a vb.net form. I don't get the message body. I have searched all over the place and found nothing. Does anyone know how to do this? I...
5
by: mars | last post by:
I use TurboGears to do some web service. TurboGears use cherrypy. When web browser access this site, the cherrypy will call my python program. So my program looks like a lib. When web browser...
3
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
9
by: Keith G Hicks | last post by:
I'm having a lot of trouble with "file in use" errors in my "folder watcher" project. Starting and stopping the watcher and reading my XML file work fine. Once the watcher is started, I'm reading...
0
by: moltendorf | last post by:
I've been trying to find a suitable method for preventing race conditions in my own code. Currently I'm using a file and the flock function to prevent code in other threads from executing at the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.