[darwinbuild-changes] [497] branches/PR-6722857/darwinup
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 25 17:30:51 PDT 2009
Revision: 497
http://trac.macosforge.org/projects/darwinbuild/changeset/497
Author: wsiegrist at apple.com
Date: 2009-03-25 17:30:51 -0700 (Wed, 25 Mar 2009)
Log Message:
-----------
Clean up our path handling. We need to add the depot prefix during backup_file for rollback archives
Modified Paths:
--------------
branches/PR-6722857/darwinup/Depot.cpp
branches/PR-6722857/darwinup/main.cpp
Modified: branches/PR-6722857/darwinup/Depot.cpp
===================================================================
--- branches/PR-6722857/darwinup/Depot.cpp 2009-03-26 00:29:32 UTC (rev 496)
+++ branches/PR-6722857/darwinup/Depot.cpp 2009-03-26 00:30:51 UTC (rev 497)
@@ -360,18 +360,9 @@
char path[PATH_MAX];
char* backup_dirpath;
- // we need the path minus our destination path for moving to the archive
- char *relpath = strstr(actual->path(), m_prefix);
- if (relpath) {
- // advance to just past the destination path
- relpath += strlen(m_prefix);
- }
+ // we need the path minus our destination prefix for moving to the archive
+ strncpy(path, actual->path() + strlen(m_prefix) - 1, PATH_MAX-1);
- size_t len = strlcpy(path, (relpath ? relpath : actual->path()),
- sizeof(path));
- assert(len <= sizeof(path));
-
-
const char* dir = dirname(path);
assert(dir != NULL);
@@ -444,21 +435,35 @@
InstallContext* context = (InstallContext*)ctx;
int res = 0;
+ IF_DEBUG("[DEBUG] backup_file: %s , %s \n", file->path(), context->archive->m_name);
+
if (INFO_TEST(file->info(), FILE_INFO_ROLLBACK_DATA)) {
- char *dstpath, *relpath, *uuidpath;
+ char *path; // the file's path
+ char *dstpath; // the path inside the archives
+ char *relpath; // the file's path minus the destination prefix
+ char *uuidpath; // archives path plus the uuid
char uuidstr[37];
+
// we need the path minus our destination path for moving to the archive
- relpath = strstr(file->path(), context->depot->m_prefix);
- if (relpath) {
- // advance to just past the destination path
- relpath += strlen(context->depot->m_prefix);
- }
+ size_t prefixlen = strlen(context->depot->m_prefix);
+ if (strncmp(context->archive->m_name, "<Rollback>", strlen("<Rollback>")) == 0) {
+ join_path(&path, context->depot->m_prefix, file->path());
+ } else {
+ asprintf(&path, "%s", file->path());
+ }
+ relpath = path;
+ if (strncmp(path, context->depot->m_prefix, prefixlen) == 0) {
+ relpath += prefixlen - 1;
+ }
+
uuid_unparse_upper(context->archive->uuid(), uuidstr);
asprintf(&uuidpath, "%s/%s", context->depot->m_archives_path, uuidstr);
assert(uuidpath != NULL);
- join_path(&dstpath, uuidpath, (relpath ? relpath : file->path()));
+ 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);
+
++context->files_modified;
// XXX: res = file->backup()
@@ -478,20 +483,21 @@
"/usr/lib/libgcc_s"};
size_t numfiles = sizeof(tarfiles)/sizeof(*tarfiles);
for (i = 0; i < numfiles; i++) {
- if (strncmp(tarfiles[i], file->path(), strlen(tarfiles[i])) == 0) {
+ if (strncmp(tarfiles[i], relpath, strlen(tarfiles[i])) == 0) {
docopy = true;
break;
}
}
if (docopy) {
- IF_DEBUG("[backup] copyfile(%s, %s)\n", file->path(), dstpath);
- res = copyfile(file->path(), dstpath, NULL, COPYFILE_ALL);
+ IF_DEBUG("[backup] copyfile(%s, %s)\n", path, dstpath);
+ res = copyfile(path, dstpath, NULL, COPYFILE_ALL);
} else {
- IF_DEBUG("[backup] rename(%s, %s)\n", file->path(), dstpath);
- res = rename(file->path(), dstpath);
+ 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);
free(uuidpath);
}
@@ -1067,6 +1073,16 @@
int Depot::insert(Archive* archive, File* file) {
int res = 0;
+
+ // check for the destination prefix in file's path, remove if found
+ char *path, *relpath;
+ size_t prefixlen = strlen(this->prefix());
+ asprintf(&path, "%s", file->path());
+ relpath = path;
+ if (strncmp(file->path(), this->prefix(), prefixlen) == 0) {
+ relpath += prefixlen - 1;
+ }
+
static sqlite3_stmt* stmt = NULL;
if (stmt == NULL && m_db) {
const char* query = "INSERT INTO files (archive, info, mode, uid, gid, digest, path) VALUES (?, ?, ?, ?, ?, ?, ?)";
@@ -1083,7 +1099,7 @@
Digest* dig = file->digest();
if (res == 0 && dig) res = sqlite3_bind_blob(stmt, i++, dig->data(), dig->size(), SQLITE_STATIC);
else if (res == 0) res = sqlite3_bind_blob(stmt, i++, NULL, 0, SQLITE_STATIC);
- if (res == 0) res = sqlite3_bind_text(stmt, i++, file->path(), -1, SQLITE_STATIC);
+ if (res == 0) res = sqlite3_bind_text(stmt, i++, relpath, -1, SQLITE_STATIC);
if (res == 0) res = sqlite3_step(stmt);
if (res == SQLITE_DONE) {
file->m_serial = (uint64_t)sqlite3_last_insert_rowid(m_db);
@@ -1093,6 +1109,7 @@
}
sqlite3_reset(stmt);
}
+ free(path);
return res;
}
Modified: branches/PR-6722857/darwinup/main.cpp
===================================================================
--- branches/PR-6722857/darwinup/main.cpp 2009-03-26 00:29:32 UTC (rev 496)
+++ branches/PR-6722857/darwinup/main.cpp 2009-03-26 00:30:51 UTC (rev 497)
@@ -54,8 +54,7 @@
int main(int argc, char* argv[]) {
char* progname = strdup(basename(argv[0]));
- char* path;
- int custom_path = 0;
+ char* path = NULL;
int ch;
while ((ch = getopt(argc, argv, "p:v")) != -1) {
@@ -69,8 +68,7 @@
fprintf(stderr, "Error: -p option value is too long \n");
exit(3);
}
- path = optarg;
- custom_path = 1;
+ join_path(&path, optarg, "/");
break;
case '?':
default:
@@ -82,7 +80,7 @@
int res = 0;
- if (!custom_path) {
+ if (!path) {
asprintf(&path, "/");
}
Depot* depot = new Depot(path);
@@ -151,9 +149,8 @@
} else {
usage(progname);
}
- if (!custom_path) {
- free(path);
- }
+
+ free(path);
exit(res);
return res;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20090325/21fdb149/attachment.html>
More information about the darwinbuild-changes
mailing list