diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2011-04-11T12·40+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2011-04-11T12·40+0000 |
commit | 08c89714984ca64b9ddfe53c99254c70a784e81c (patch) | |
tree | e22cafe17c17b1d6df65db16de1fa16c82d5c5b6 /scripts/NixManifest.pm.in | |
parent | b2c11b9ed05d33bb938d83fbcb367256427450f6 (diff) |
* Lock the database during updates.
Diffstat (limited to 'scripts/NixManifest.pm.in')
-rw-r--r-- | scripts/NixManifest.pm.in | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/scripts/NixManifest.pm.in b/scripts/NixManifest.pm.in index 4dda69710d7f..20749acd7e40 100644 --- a/scripts/NixManifest.pm.in +++ b/scripts/NixManifest.pm.in @@ -3,6 +3,7 @@ use DBI; use Cwd; use File::stat; use File::Path; +use Fcntl ':flock'; sub addPatch { @@ -259,7 +260,11 @@ EOF $dbh->do("create index if not exists Patches_storePath on Patches(storePath)"); - # !!! locking? + # Acquire an exclusive lock to ensure that only one process + # updates the DB at the same time. This isn't really necessary, + # but it prevents work duplication and lock contention in SQLite. + open MAINLOCK, ">>$manifestDir/cache.lock" or die; + flock(MAINLOCK, LOCK_EX) or die; # Read each manifest in $manifestDir and add it to the database, # unless we've already done so on a previous run. @@ -326,6 +331,8 @@ EOF $dbh->commit; + close MAINLOCK; + return $dbh; } |