[darwinbuild-changes] [651] trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Dec 10 14:38:37 PST 2009
Revision: 651
http://trac.macosforge.org/projects/darwinbuild/changeset/651
Author: wsiegrist at apple.com
Date: 2009-12-10 14:38:33 -0800 (Thu, 10 Dec 2009)
Log Message:
-----------
Merging PR-6634286 and PR-7250612
Modified Paths:
--------------
trunk/darwinup/Depot.cpp
trunk/darwinup/Depot.h
trunk/darwinup/File.cpp
trunk/darwinup/main.cpp
trunk/testing/darwinup/run-tests.sh
Added Paths:
-----------
trunk/testing/darwinup/root4.tar.gz
Property Changed:
----------------
trunk/
trunk/darwinbuild/darwinbuild.in
trunk/darwinbuild/darwinmaster.in
trunk/darwinbuild/installXcode.in
trunk/darwinbuild/packageRoots.in
trunk/darwinbuild/thinPackages.in
Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/PR-4841388:399-419
/branches/PR-6358021:442-443
/branches/PR-6392966:423-427
/branches/PR-6398060:433-434
/branches/PR-6493844:460-461
/branches/PR-6497694:466-468,471
/branches/PR-6688645:479-490
/branches/PR-6722857:495-499
/trunk:432-434
+ /branches/PR-4841388:399-419
/branches/PR-6358021:442-443
/branches/PR-6392966:423-427
/branches/PR-6398060:433-434
/branches/PR-6493844:460-461
/branches/PR-6497694:466-468,471
/branches/PR-6634286:632-650
/branches/PR-6688645:479-490
/branches/PR-6722857:495-499
/branches/PR-7250612:635-650
/trunk:432-434
Property changes on: trunk/darwinbuild/darwinbuild.in
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/PR-4841388/darwinbuild/darwinbuild:399-419
/branches/PR-6358021/darwinbuild/darwinbuild:442-443
/branches/PR-6392966/darwinbuild/darwinbuild:423-427
/branches/PR-6398060/darwinbuild/darwinbuild:433-434
/branches/PR-6493844/darwinbuild/darwinbuild.in:460-461
/branches/PR-6497694/darwinbuild/darwinbuild.in:466-468,471
/branches/PR-6688645/darwinbuild/darwinbuild.in:479-490
/branches/PR-6722857/darwinbuild/darwinbuild.in:495-499
/trunk/darwinbuild/darwinbuild:432-434
+ /branches/PR-4841388/darwinbuild/darwinbuild:399-419
/branches/PR-6358021/darwinbuild/darwinbuild:442-443
/branches/PR-6392966/darwinbuild/darwinbuild:423-427
/branches/PR-6398060/darwinbuild/darwinbuild:433-434
/branches/PR-6493844/darwinbuild/darwinbuild.in:460-461
/branches/PR-6497694/darwinbuild/darwinbuild.in:466-468,471
/branches/PR-6634286/darwinbuild/darwinbuild.in:632-650
/branches/PR-6688645/darwinbuild/darwinbuild.in:479-490
/branches/PR-6722857/darwinbuild/darwinbuild.in:495-499
/branches/PR-7250612/darwinbuild/darwinbuild.in:635-650
/trunk/darwinbuild/darwinbuild:432-434
Property changes on: trunk/darwinbuild/darwinmaster.in
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/PR-4841388/darwinbuild/darwinmaster.sh:399-419
/branches/PR-6358021/darwinbuild/darwinmaster.sh:442-443
/branches/PR-6392966/darwinbuild/darwinmaster.sh:423-427
/branches/PR-6398060/darwinbuild/darwinmaster.sh:433-434
/branches/PR-6493844/darwinbuild/darwinmaster.sh.in:460-461
/branches/PR-6497694/darwinbuild/darwinmaster.sh.in:466-468,471
/branches/PR-6688645/darwinbuild/darwinmaster.sh.in:479-490
/branches/PR-6722857/darwinbuild/darwinmaster.sh.in:495-499
/trunk/darwinbuild/darwinmaster.sh:432-434
+ /branches/PR-4841388/darwinbuild/darwinmaster.sh:399-419
/branches/PR-6358021/darwinbuild/darwinmaster.sh:442-443
/branches/PR-6392966/darwinbuild/darwinmaster.sh:423-427
/branches/PR-6398060/darwinbuild/darwinmaster.sh:433-434
/branches/PR-6493844/darwinbuild/darwinmaster.sh.in:460-461
/branches/PR-6497694/darwinbuild/darwinmaster.sh.in:466-468,471
/branches/PR-6634286/darwinbuild/darwinmaster.in:632-650
/branches/PR-6688645/darwinbuild/darwinmaster.sh.in:479-490
/branches/PR-6722857/darwinbuild/darwinmaster.sh.in:495-499
/branches/PR-7250612/darwinbuild/darwinmaster.in:635-650
/trunk/darwinbuild/darwinmaster.sh:432-434
Property changes on: trunk/darwinbuild/installXcode.in
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/PR-4841388/darwinbuild/installXcode:399-419
/branches/PR-6358021/darwinbuild/installXcode:442-443
/branches/PR-6392966/darwinbuild/installXcode:423-427
/branches/PR-6398060/darwinbuild/installXcode:433-434
/branches/PR-6493844/darwinbuild/installXcode.in:460-461
/branches/PR-6497694/darwinbuild/installXcode.in:466-468,471
/branches/PR-6688645/darwinbuild/installXcode.in:479-490
/branches/PR-6722857/darwinbuild/installXcode.in:495-499
/trunk/darwinbuild/installXcode:432-434
+ /branches/PR-4841388/darwinbuild/installXcode:399-419
/branches/PR-6358021/darwinbuild/installXcode:442-443
/branches/PR-6392966/darwinbuild/installXcode:423-427
/branches/PR-6398060/darwinbuild/installXcode:433-434
/branches/PR-6493844/darwinbuild/installXcode.in:460-461
/branches/PR-6497694/darwinbuild/installXcode.in:466-468,471
/branches/PR-6634286/darwinbuild/installXcode.in:632-650
/branches/PR-6688645/darwinbuild/installXcode.in:479-490
/branches/PR-6722857/darwinbuild/installXcode.in:495-499
/branches/PR-7250612/darwinbuild/installXcode.in:635-650
/trunk/darwinbuild/installXcode:432-434
Property changes on: trunk/darwinbuild/packageRoots.in
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/PR-4841388/darwinbuild/packageRoots.sh:399-419
/branches/PR-6358021/darwinbuild/packageRoots.sh:442-443
/branches/PR-6392966/darwinbuild/packageRoots.sh:423-427
/branches/PR-6398060/darwinbuild/packageRoots.sh:433-434
/branches/PR-6493844/darwinbuild/packageRoots.sh.in:460-461
/branches/PR-6497694/darwinbuild/packageRoots.sh.in:466-468,471
/branches/PR-6688645/darwinbuild/packageRoots.sh.in:479-490
/branches/PR-6722857/darwinbuild/packageRoots.sh.in:495-499
/trunk/darwinbuild/packageRoots.sh:432-434
+ /branches/PR-4841388/darwinbuild/packageRoots.sh:399-419
/branches/PR-6358021/darwinbuild/packageRoots.sh:442-443
/branches/PR-6392966/darwinbuild/packageRoots.sh:423-427
/branches/PR-6398060/darwinbuild/packageRoots.sh:433-434
/branches/PR-6493844/darwinbuild/packageRoots.sh.in:460-461
/branches/PR-6497694/darwinbuild/packageRoots.sh.in:466-468,471
/branches/PR-6634286/darwinbuild/packageRoots.in:632-650
/branches/PR-6688645/darwinbuild/packageRoots.sh.in:479-490
/branches/PR-6722857/darwinbuild/packageRoots.sh.in:495-499
/branches/PR-7250612/darwinbuild/packageRoots.in:635-650
/trunk/darwinbuild/packageRoots.sh:432-434
Property changes on: trunk/darwinbuild/thinPackages.in
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/PR-4841388/darwinbuild/thinPackages.sh:399-419
/branches/PR-6358021/darwinbuild/thinPackages.sh:442-443
/branches/PR-6392966/darwinbuild/thinPackages.sh:423-427
/branches/PR-6398060/darwinbuild/thinPackages.sh:433-434
/branches/PR-6493844/darwinbuild/thinPackages.sh.in:460-461
/branches/PR-6497694/darwinbuild/thinPackages.sh.in:466-468,471
/branches/PR-6688645/darwinbuild/thinPackages.sh.in:479-490
/branches/PR-6722857/darwinbuild/thinPackages.sh.in:495-499
/trunk/darwinbuild/thinPackages.sh:432-434
+ /branches/PR-4841388/darwinbuild/thinPackages.sh:399-419
/branches/PR-6358021/darwinbuild/thinPackages.sh:442-443
/branches/PR-6392966/darwinbuild/thinPackages.sh:423-427
/branches/PR-6398060/darwinbuild/thinPackages.sh:433-434
/branches/PR-6493844/darwinbuild/thinPackages.sh.in:460-461
/branches/PR-6497694/darwinbuild/thinPackages.sh.in:466-468,471
/branches/PR-6634286/darwinbuild/thinPackages.in:632-650
/branches/PR-6688645/darwinbuild/thinPackages.sh.in:479-490
/branches/PR-6722857/darwinbuild/thinPackages.sh.in:495-499
/branches/PR-7250612/darwinbuild/thinPackages.in:635-650
/trunk/darwinbuild/thinPackages.sh:432-434
Modified: trunk/darwinup/Depot.cpp
===================================================================
--- trunk/darwinup/Depot.cpp 2009-12-10 22:05:22 UTC (rev 650)
+++ trunk/darwinup/Depot.cpp 2009-12-10 22:38:33 UTC (rev 651)
@@ -42,62 +42,85 @@
#include <sqlite3.h>
Depot::Depot() {
- m_prefix = NULL;
+ m_prefix = NULL;
m_depot_path = NULL;
m_database_path = NULL;
m_archives_path = NULL;
m_db = NULL;
m_lock_fd = -1;
m_is_locked = 0;
+ m_depot_mode = 0750;
}
Depot::Depot(const char* prefix) {
m_lock_fd = -1;
m_is_locked = 0;
+ m_depot_mode = 0750;
+
asprintf(&m_prefix, "%s", prefix);
join_path(&m_depot_path, m_prefix, "/.DarwinDepot");
join_path(&m_database_path, m_depot_path, "/Database-V100");
join_path(&m_archives_path, m_depot_path, "/Archives");
+}
- mkdir(m_depot_path, m_depot_mode);
- mkdir(m_archives_path, m_depot_mode);
+Depot::~Depot() {
+ if (m_lock_fd != -1) this->unlock();
+ if (m_db) sqlite3_close(m_db);
+ if (m_prefix) free(m_prefix);
+ if (m_depot_path) free(m_depot_path);
+ if (m_database_path) free(m_database_path);
+ if (m_archives_path) free(m_archives_path);
+}
+const char* Depot::archives_path() { return m_archives_path; }
+const char* Depot::prefix() { return m_prefix; }
+
+// Initialize the depot storage on disk
+int Depot::initialize() {
int res = 0;
-
+
+ // initialization requires all these paths to be set
+ if (!(m_prefix && m_depot_path && m_database_path && m_archives_path)) {
+ return -1;
+ }
+
+ res = mkdir(m_depot_path, m_depot_mode);
+ if (res && errno != EEXIST) {
+ perror(m_depot_path);
+ return res;
+ }
+ res = mkdir(m_archives_path, m_depot_mode);
+ if (res && errno != EEXIST) {
+ perror(m_archives_path);
+ return res;
+ }
+
res = this->lock(LOCK_SH);
- if (res == 0) {
- m_is_locked = 1;
- }
-
+ if (res) return res;
+ m_is_locked = 1;
+
int exists = is_regular_file(m_database_path);
-
+
res = sqlite3_open(m_database_path, &m_db);
- if (res != 0) {
+ if (res) {
sqlite3_close(m_db);
m_db = NULL;
}
-
+
if (m_db && !exists) {
this->SQL("CREATE TABLE archives (serial INTEGER PRIMARY KEY AUTOINCREMENT, uuid BLOB UNIQUE, name TEXT, date_added INTEGER, active INTEGER, info INTEGER)");
this->SQL("CREATE TABLE files (serial INTEGER PRIMARY KEY AUTOINCREMENT, archive INTEGER, info INTEGER, mode INTEGER, uid INTEGER, gid INTEGER, size INTEGER, digest BLOB, path TEXT)");
-
this->SQL("CREATE INDEX archives_uuid ON archives (uuid)");
this->SQL("CREATE INDEX files_path ON files (path)");
}
+
+ return res;
}
-Depot::~Depot() {
- if (m_lock_fd != -1) this->unlock();
- if (m_db) sqlite3_close(m_db);
- if (m_prefix) free(m_prefix);
- if (m_depot_path) free(m_depot_path);
- if (m_database_path) free(m_database_path);
- if (m_archives_path) free(m_archives_path);
+int Depot::is_initialized() {
+ return (m_db != NULL);
}
-const char* Depot::archives_path() { return m_archives_path; }
-const char* Depot::prefix() { return m_prefix; }
-
// Unserialize an archive from the database.
// Find the archive by UUID.
// XXX: should be memoized
@@ -435,7 +458,7 @@
InstallContext* context = (InstallContext*)ctx;
int res = 0;
- IF_DEBUG("[DEBUG] backup_file: %s , %s \n", file->path(), context->archive->m_name);
+ IF_DEBUG("[backup] backup_file: %s , %s \n", file->path(), context->archive->m_name);
if (INFO_TEST(file->info(), FILE_INFO_ROLLBACK_DATA)) {
char *path; // the file's path
@@ -462,41 +485,17 @@
join_path(&dstpath, uuidpath, relpath);
assert(dstpath != NULL);
- IF_DEBUG("[DEBUG] \npath = %s \nrelpath = %s \ndstpath = %s \nuuidpath = %s \n[/DEBUG]\n", path, relpath, dstpath, uuidpath);
+ IF_DEBUG("[backup] path = %s \n", path);
+ IF_DEBUG("[backup] relpath = %s \n", relpath);
+ IF_DEBUG("[backup] dstpath = %s \n", dstpath);
+ IF_DEBUG("[backup] uuidpath = %s \n", uuidpath);
++context->files_modified;
// XXX: res = file->backup()
+ IF_DEBUG("[backup] copyfile(%s, %s)\n", path, dstpath);
+ res = copyfile(path, dstpath, NULL, COPYFILE_ALL);
- // copy files used by gnutar and libarchive instead of moving them
- // since we use tar during the archive process
- size_t i = 0;
- bool docopy = false;
- const char* tarfiles[] = {"/usr/bin/tar",
- "/usr/bin/gnutar",
- "/usr/bin/bsdtar",
- "/usr/lib/dyld",
- "/usr/lib/libarchive",
- "/usr/lib/libbz2",
- "/usr/lib/libz",
- "/usr/lib/libSystem",
- "/usr/lib/libiconv",
- "/usr/lib/libgcc_s"};
- size_t numfiles = sizeof(tarfiles)/sizeof(*tarfiles);
- for (i = 0; i < numfiles; i++) {
- if (strncmp(tarfiles[i], relpath, strlen(tarfiles[i])) == 0) {
- docopy = true;
- break;
- }
- }
- if (docopy) {
- IF_DEBUG("[backup] copyfile(%s, %s)\n", path, dstpath);
- res = copyfile(path, dstpath, NULL, COPYFILE_ALL);
- } else {
- IF_DEBUG("[backup] rename(%s, %s)\n", path, dstpath);
- res = rename(path, dstpath);
- }
-
if (res != 0) fprintf(stderr, "%s:%d: backup failed: %s: %s (%d)\n", __FILE__, __LINE__, dstpath, strerror(errno), errno);
free(path);
free(dstpath);
@@ -1022,9 +1021,10 @@
m_lock_fd = open(m_depot_path, O_RDONLY);
if (m_lock_fd == -1) {
perror(m_depot_path);
- res = -1;
+ res = m_lock_fd;
}
}
+ if (res) return res;
res = flock(m_lock_fd, operation);
if (res == -1) {
perror(m_depot_path);
Modified: trunk/darwinup/Depot.h
===================================================================
--- trunk/darwinup/Depot.h 2009-12-10 22:05:22 UTC (rev 650)
+++ trunk/darwinup/Depot.h 2009-12-10 22:38:33 UTC (rev 651)
@@ -37,6 +37,9 @@
virtual ~Depot();
+ int initialize();
+ int is_initialized();
+
const char* prefix();
const char* database_path();
const char* archives_path();
Modified: trunk/darwinup/File.cpp
===================================================================
--- trunk/darwinup/File.cpp 2009-12-10 22:05:22 UTC (rev 650)
+++ trunk/darwinup/File.cpp 2009-12-10 22:38:33 UTC (rev 651)
@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <removefile.h>
File::File() {
m_serial = 0;
@@ -133,6 +134,7 @@
}
int File::install(const char* prefix, const char* dest) {
+ extern uint32_t force;
int res = 0;
Archive* archive = this->archive();
assert(archive != NULL);
@@ -150,29 +152,57 @@
fprintf(stderr, "ERROR: [install] path too long: %s/%s\n", dirpath, path);
return -1;
}
- IF_DEBUG("[install] about to rename %s to %s\n", srcpath, dstpath);
+ IF_DEBUG("[install] rename(%s, %s)\n", srcpath, dstpath);
res = rename(srcpath, dstpath);
if (res == -1) {
if (errno == ENOENT) {
// the file wasn't found, try to do on-demand
// expansion of the archive that contains it.
if (is_directory(dirpath) == 0) {
+ IF_DEBUG("[install] File::install on-demand archive expansion \n");
res = archive->expand_directory(prefix);
if (res == 0) res = this->install(prefix, dest);
} else {
// archive was already expanded, so
// the file is truly missing (worry).
+ IF_DEBUG("[install] File::install missing file in archive \n");
fprintf(stderr, "%s:%d: %s: %s (%d)\n", __FILE__, __LINE__, srcpath, strerror(errno), errno);
}
- //} else if (errno == ENOTDIR) {
+ } else if (force && errno == ENOTDIR) {
// a) some part of destination path does not exist
// b) from is a directory, but to is not
- //} else if (errno == EISDIR) {
+ IF_DEBUG("[install] File::install ENOTDIR\n");
+ fprintf(stderr, "%s:%d: %s: %s (%d)\n", __FILE__, __LINE__, dstpath, strerror(errno), errno);
+ } else if (force && errno == EISDIR) {
// to is a directory, but from is not
- //} else if (errno == ENOTEMPTY) {
+ IF_DEBUG("[install] replacing directory with a file\n");
+ IF_DEBUG("[install] removefile(%s)\n", dstpath);
+ removefile_state_t rmstate;
+ rmstate = removefile_state_alloc();
+ res = removefile(dstpath, rmstate, REMOVEFILE_RECURSIVE);
+ removefile_state_free(rmstate);
+ if (res == -1) fprintf(stderr, "%s:%d: %s: %s (%d)\n", __FILE__, __LINE__, dstpath, strerror(errno), errno);
+ IF_DEBUG("[install] rename(%s, %s)\n", srcpath, dstpath);
+ res = rename(srcpath, dstpath);
+ if (res == -1) fprintf(stderr, "%s:%d: %s: %s (%d)\n", __FILE__, __LINE__, dstpath, strerror(errno), errno);
+ } else if (force && errno == ENOTEMPTY) {
// to is a directory and is not empty
+ IF_DEBUG("[install] File::install ENOTEMPTY\n");
+ fprintf(stderr, "%s:%d: %s: %s (%d)\n", __FILE__, __LINE__, dstpath, strerror(errno), errno);
} else {
+ if (!force) {
+ fprintf(stderr,
+ "-------------------------------------------------------------------------------\n"
+ "darwinup has encountered a potentially unsafe mismatch between the root and \n"
+ "destination. For example, you may be trying to install a file where a directory\n"
+ "currently exists. darwinup will not install this root by default since it could\n"
+ "cause damage to your system. You can use the force (-f) option to allow \n"
+ "darwinup to attempt the install anyway. \n"
+ "-------------------------------------------------------------------------------\n"
+ );
+ }
fprintf(stderr, "%s:%d: %s: %s (%d)\n", __FILE__, __LINE__, dstpath, strerror(errno), errno);
+ fprintf(stderr, "ERROR: fatal error during File::install. Cannot continue.\n");
}
} else {
IF_DEBUG("[install] rename(%s, %s)\n", srcpath, dstpath);
@@ -266,14 +296,17 @@
int Symlink::install_info(const char* dest) {
int res = 0;
- const char* path = this->path();
+ char* path;
+ join_path(&path, dest, this->path());
//mode_t mode = this->mode() & ALLPERMS;
uid_t uid = this->uid();
gid_t gid = this->gid();
IF_DEBUG("[install] lchown(%d, %d)\n", uid, gid);
if (res == 0) res = lchown(path, uid, gid);
+ if (res == -1) fprintf(stderr, "%s:%d: %s: %s (%d)\n", __FILE__, __LINE__, path, strerror(errno), errno);
//IF_DEBUG("[install] lchmod(%o)\n", mode);
//if (res == 0) res = lchmod(path, mode);
+ free(path);
return res;
}
@@ -286,7 +319,7 @@
// existing one, since that would move the entire
// sub-tree, and lead to a lot of ENOENT errors.
int res = 0;
-
+ extern uint32_t force;
char* dstpath;
join_path(&dstpath, dest, this->path());
@@ -296,10 +329,38 @@
IF_DEBUG("[install] mkdir(%s, %04o)\n", dstpath, mode);
if (res == 0) res = mkdir(dstpath, mode);
- if (res != 0) fprintf(stderr, "ERROR: %s:%d: %s: %s (%d)\n", __FILE__, __LINE__, dstpath, strerror(errno), errno);
- if (res == 0) res = chown(dstpath, uid, gid);
- if (res != 0) fprintf(stderr, "ERROR: %s:%d: %s: %s (%d)\n", __FILE__, __LINE__, dstpath, strerror(errno), errno);
+ if (res && errno == EEXIST) {
+ if (is_directory(dstpath)) {
+ // this is expected in normal cases, so no need to force
+ IF_DEBUG("[install] directory already exists, setting mode \n");
+ res = chmod(dstpath, mode);
+ if (res == -1) fprintf(stderr, "%s:%d: %s: %s (%d)\n", __FILE__, __LINE__, dstpath, strerror(errno), errno);
+ } else if (force) {
+ // this could be bad, so require the force option
+ IF_DEBUG("[install] original node is a file, we need to replace with a directory \n");
+ IF_DEBUG("[install] unlink(%s)\n", dstpath);
+ res = unlink(dstpath);
+ IF_DEBUG("[install] mkdir(%s, %04o)\n", dstpath, mode);
+ res = mkdir(dstpath, mode);
+ if (res == -1) fprintf(stderr, "%s:%d: %s: %s (%d)\n", __FILE__, __LINE__, dstpath, strerror(errno), errno);
+ }
+ } else if (force && res == -1 && errno == ENOTDIR) {
+ // some part of destination path is not a directory
+ IF_DEBUG("[install] Directory::install ENOTDIR \n");
+ } else if (res == -1) {
+ fprintf(stderr, "ERROR: %s:%d: %s: %s (%d)\n", __FILE__, __LINE__, dstpath, strerror(errno), errno);
+ fprintf(stderr, "ERROR: unable to create %s \n", dstpath);
+ }
+
+ if (res == 0) {
+ res = chown(dstpath, uid, gid);
+ if (res != 0) {
+ fprintf(stderr, "ERROR: %s:%d: %s: %s (%d)\n", __FILE__, __LINE__, dstpath, strerror(errno), errno);
+ fprintf(stderr, "ERROR: unable to change ownership of %s \n", dstpath);
+ }
+ }
+
free(dstpath);
return res;
}
@@ -376,12 +437,22 @@
File* file = NULL;
struct stat sb;
int res = 0;
+ extern uint32_t force;
res = lstat(path, &sb);
if (res == -1 && errno == ENOENT) {
+ // destination does not have a matching node
return NULL;
- } else if (res == -1) {
+ } else if (force && res == -1 && errno == ENOTDIR) {
+ // some part of destination path does not exist
+ // or is a file. This gets handled by Directory::install
+ // eventually
+ IF_DEBUG("[factory] parents do not exist or contain a file\n");
+ return NULL;
+ }
+ if (res == -1) {
fprintf(stderr, "%s:%d: %s: %s (%d)\n", __FILE__, __LINE__, path, strerror(errno), errno);
+ fprintf(stderr, "ERROR: unable to stat %s \n", path);
return NULL;
}
Modified: trunk/darwinup/main.cpp
===================================================================
--- trunk/darwinup/main.cpp 2009-12-10 22:05:22 UTC (rev 650)
+++ trunk/darwinup/main.cpp 2009-12-10 22:38:33 UTC (rev 651)
@@ -36,6 +36,7 @@
fprintf(stderr, "usage: %s [-v] [-p DIR] [command] [args] \n", progname);
fprintf(stderr, " \n");
fprintf(stderr, "options: \n");
+ fprintf(stderr, " -f force operation to succeed at all costs \n");
fprintf(stderr, " -p DIR operate on roots under DIR (default: /) \n");
fprintf(stderr, " -v verbose (use -vv for extra verbosity) \n");
fprintf(stderr, " \n");
@@ -50,6 +51,7 @@
// our globals
uint32_t verbosity;
+uint32_t force;
int main(int argc, char* argv[]) {
char* progname = strdup(basename(argv[0]));
@@ -57,41 +59,56 @@
char* path = NULL;
int ch;
- while ((ch = getopt(argc, argv, "p:v")) != -1) {
+ while ((ch = getopt(argc, argv, "fp:vh")) != -1) {
switch (ch) {
+ case 'f':
+ IF_DEBUG("forcing operations\n");
+ force = 1;
+ break;
+ case 'p':
+ if (optarg[0] != '/') {
+ fprintf(stderr, "Error: -p option must be an absolute path\n");
+ exit(4);
+ }
+ if (strlen(optarg) > (PATH_MAX - 1)) {
+ fprintf(stderr, "Error: -p option value is too long \n");
+ exit(4);
+ }
+ join_path(&path, optarg, "/");
+ break;
case 'v':
- verbosity <<= 1;
- verbosity |= VERBOSE;
- break;
- case 'p':
- if (strlen(optarg) > (PATH_MAX - 1)) {
- fprintf(stderr, "Error: -p option value is too long \n");
- exit(3);
- }
- join_path(&path, optarg, "/");
- break;
+ verbosity <<= 1;
+ verbosity |= VERBOSE;
+ break;
case '?':
+ case 'h':
default:
- usage(progname);
+ usage(progname);
}
}
argc -= optind;
argv += optind;
+ // you must be root
+ uid_t uid = getuid();
+ if (uid) {
+ fprintf(stderr, "You must be root to run this tool.\n");
+ exit(3);
+ }
+
int res = 0;
if (!path) {
asprintf(&path, "/");
}
+
Depot* depot = new Depot(path);
- if (!depot->is_locked()) {
- fprintf(stderr,
- "Error: unable to access and lock %s. " \
- "The directory must exist and be writable.\n", depot->prefix());
+ res = depot->initialize();
+ if (res) {
+ fprintf(stderr, "Error: unable to initialize storage.\n");
exit(2);
}
-
-
+
if (argc == 2 && strcmp(argv[0], "install") == 0) {
char uuid[37];
Archive* archive = ArchiveFactory(argv[1]);
@@ -101,7 +118,14 @@
uuid_unparse_upper(archive->uuid(), uuid);
fprintf(stdout, "%s\n", uuid);
} else {
- fprintf(stderr, "An error occurred.\n");
+ fprintf(stderr, "Error: Install failed. Rolling back installation.\n");
+ res = depot->uninstall(archive);
+ if (res) {
+ fprintf(stderr, "Error: Unable to rollback installation. "
+ "Your system is in an inconsistent state! File a bug!\n");
+ } else {
+ fprintf(stderr, "Rollback successful.\n");
+ }
res = 1;
}
} else {
Copied: trunk/testing/darwinup/root4.tar.gz (from rev 650, branches/PR-7250612/testing/darwinup/root4.tar.gz)
===================================================================
(Binary files differ)
Modified: trunk/testing/darwinup/run-tests.sh
===================================================================
--- trunk/testing/darwinup/run-tests.sh 2009-12-10 22:05:22 UTC (rev 650)
+++ trunk/testing/darwinup/run-tests.sh 2009-12-10 22:38:33 UTC (rev 651)
@@ -22,6 +22,7 @@
do
tar zxvf $R.tar.gz -C $PREFIX
done;
+tar zxvf root4.tar.gz -C $PREFIX
mkdir -p $ORIG
cp -R $DEST/* $ORIG/
@@ -108,6 +109,11 @@
echo "DIFF: diffing original test files to dest (should be no diffs) ..."
diff -qru $ORIG $DEST 2>&1 | grep -v \\.DarwinDepot
+echo "TEST: Trying a root that will fail due to object change ..."
+darwinup -vv -p $DEST install $PREFIX/root4
+if [ $? -ne 1 ]; then exit 1; fi
+echo "DIFF: diffing original test files to dest (should be no diffs) ..."
+diff -qru $ORIG $DEST 2>&1 | grep -v \\.DarwinDepot
echo "INFO: Done testing!"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20091210/d517716e/attachment-0001.html>
More information about the darwinbuild-changes
mailing list