Page 1 of 1

Thread safe file system access

Posted: Tue Feb 17, 2004 8:53 am
by greenhorn666
I am about to create an update system for a database that uses a CSV file to update/insert rows in postgresql database's tables.

I was thinking of a crontab entry that scans the FS for a newer upload than it's last execution time (about every minute). If a file is present it launches the update script. The problem I see coming is 'What if the upload isn't terminated yet?'
Well, in our case here it wouldn't be that bad, since only valid cvs lines will go for the update that itselfs happens in a transaction.

But is there a way to verify that no file descriptor is open the file before proceeding with the update? or any other solution, hint, idea is welcome...

Otherwise I'll go for a #!/bin/bash with lsof on the file...

Posted: Tue Feb 17, 2004 11:00 am
by McGruff
In the upload script, the final action could be to log upload success somewhere.

Update script could check the log entries before proceeding.

Posted: Tue Feb 17, 2004 11:04 am
by greenhorn666
Well since the upload happens over FTP, I can make have php to create a lock file somewhere... I've done it with a small bash script using lsof to check if the file is still in use...
Thanks anyhow ;)