[darwinbuild-changes] [481] branches/PR-6688645/darwinup
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 18 13:32:05 PDT 2009
Revision: 481
http://trac.macosforge.org/projects/darwinbuild/changeset/481
Author: wsiegrist at apple.com
Date: 2009-03-18 13:32:05 -0700 (Wed, 18 Mar 2009)
Log Message:
-----------
Add a flag to the Depot so we can test for a successful lock and exit earlier when we cannot access the path
Modified Paths:
--------------
branches/PR-6688645/darwinup/Depot.cpp
branches/PR-6688645/darwinup/Depot.h
branches/PR-6688645/darwinup/main.cpp
Modified: branches/PR-6688645/darwinup/Depot.cpp
===================================================================
--- branches/PR-6688645/darwinup/Depot.cpp 2009-03-18 19:31:35 UTC (rev 480)
+++ branches/PR-6688645/darwinup/Depot.cpp 2009-03-18 20:32:05 UTC (rev 481)
@@ -48,11 +48,12 @@
m_archives_path = NULL;
m_db = NULL;
m_lock_fd = -1;
+ m_is_locked = 0;
}
Depot::Depot(const char* prefix) {
m_lock_fd = -1;
-
+ m_is_locked = 0;
asprintf(&m_prefix, "%s", prefix);
asprintf(&m_depot_path, "%s/.DarwinDepot", m_prefix);
asprintf(&m_database_path, "%s/Database-V100", m_depot_path);
@@ -62,7 +63,6 @@
mkdir(m_archives_path, m_depot_mode);
(void)this->lock(LOCK_SH);
-
int exists = is_regular_file(m_database_path);
int res = sqlite3_open(m_database_path, &m_db);
@@ -978,8 +978,13 @@
return this->SQL("COMMIT TRANSACTION");
}
+int Depot::is_locked() { return m_is_locked; }
+
int Depot::lock(int operation) {
int res = 0;
+ if (m_is_locked) {
+ fprintf(stderr, "Warning: attempt to over lock the depot\n");
+ }
if (m_lock_fd == -1) {
m_lock_fd = open(m_depot_path, O_RDONLY);
if (m_lock_fd == -1) {
@@ -990,15 +995,22 @@
res = flock(m_lock_fd, operation);
if (res == -1) {
perror(m_depot_path);
+ } else {
+ m_is_locked = 1;
}
return res;
}
int Depot::unlock(void) {
int res = 0;
+ if (!m_is_locked) {
+ fprintf(stderr, "Warning: attempt to over unlock the depot\n");
+ }
res = flock(m_lock_fd, LOCK_UN);
if (res == -1) {
perror(m_depot_path);
+ } else {
+ m_is_locked = 0;
}
close(m_lock_fd);
m_lock_fd = -1;
Modified: branches/PR-6688645/darwinup/Depot.h
===================================================================
--- branches/PR-6688645/darwinup/Depot.h 2009-03-18 19:31:35 UTC (rev 480)
+++ branches/PR-6688645/darwinup/Depot.h 2009-03-18 20:32:05 UTC (rev 481)
@@ -71,6 +71,9 @@
int iterate_files(Archive* archive, FileIteratorFunc func, void* context);
int iterate_archives(ArchiveIteratorFunc func, void* context);
+ // test if the depot is currently locked
+ int is_locked();
+
protected:
// Serialize access to the Depot via flock(2).
@@ -116,4 +119,5 @@
char* m_database_path;
char* m_archives_path;
int m_lock_fd;
+ int m_is_locked;
};
Modified: branches/PR-6688645/darwinup/main.cpp
===================================================================
--- branches/PR-6688645/darwinup/main.cpp 2009-03-18 19:31:35 UTC (rev 480)
+++ branches/PR-6688645/darwinup/main.cpp 2009-03-18 20:32:05 UTC (rev 481)
@@ -33,10 +33,10 @@
#include <limits.h>
void usage(char* progname) {
- fprintf(stderr, "usage: %s [-v] [-p PATH] [command] [args] \n", progname);
+ fprintf(stderr, "usage: %s [-v] [-p DIR] [command] [args] \n", progname);
fprintf(stderr, " \n");
fprintf(stderr, "options: \n");
- fprintf(stderr, " -p PATH install roots to partition (default: /) \n");
+ fprintf(stderr, " -p DIR install roots under DIR (default: /) \n");
fprintf(stderr, " -v verbose (use -vv for extra verbosity) \n");
fprintf(stderr, " \n");
fprintf(stderr, "commands: \n");
@@ -79,7 +79,14 @@
int res = 0;
Depot* depot = new Depot(partition);
+ if (!depot->is_locked()) {
+ fprintf(stderr,
+ "Error: unable to access and lock %s. " \
+ "The directory must exist and be writable.\n", depot->prefix());
+ exit(2);
+ }
+
if (argc == 2 && strcmp(argv[0], "install") == 0) {
char uuid[37];
Archive* archive = ArchiveFactory(argv[1]);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20090318/44865b59/attachment-0001.html>
More information about the darwinbuild-changes
mailing list