[darwinbuild-changes] [488] branches/PR-6688645
source_changes at macosforge.org
source_changes at macosforge.org
Thu Mar 19 13:03:05 PDT 2009
Revision: 488
http://trac.macosforge.org/projects/darwinbuild/changeset/488
Author: wsiegrist at apple.com
Date: 2009-03-19 13:03:05 -0700 (Thu, 19 Mar 2009)
Log Message:
-----------
Add a path joining function in order to remove extra slashes when joining path elements. This fixes the problem of paths stored in sqlite not being string equal even when they are the same filesystem object.
Modified Paths:
--------------
branches/PR-6688645/common.mk
branches/PR-6688645/darwinup/Depot.cpp
branches/PR-6688645/darwinup/File.cpp
branches/PR-6688645/darwinup/Utils.cpp
branches/PR-6688645/darwinup/Utils.h
Modified: branches/PR-6688645/common.mk
===================================================================
--- branches/PR-6688645/common.mk 2009-03-19 01:44:32 UTC (rev 487)
+++ branches/PR-6688645/common.mk 2009-03-19 20:03:05 UTC (rev 488)
@@ -5,6 +5,7 @@
DESTDIR?=$(DSTROOT)
### makefile variables normally set by XBS
+SRCROOT?=.
OBJROOT?=.
SYMROOT?=.
@@ -20,6 +21,6 @@
SED=/usr/bin/sed
-RC_CFLAGS?=$(shell lipo -info /usr/lib/libSystem.dylib | cut -d : -f 3 | sed 's/ppc7400/ppc/' | awk '{ ORS=" "; for(i=1;i<=NF;i++) print "-arch", $$i}')
+RC_CFLAGS?=$(shell ../archs.sh | awk '{ ORS=" "; for(i=1;i<=NF;i++) print "-arch", $$i}')
CFLAGS+=$(RC_CFLAGS)
Modified: branches/PR-6688645/darwinup/Depot.cpp
===================================================================
--- branches/PR-6688645/darwinup/Depot.cpp 2009-03-19 01:44:32 UTC (rev 487)
+++ branches/PR-6688645/darwinup/Depot.cpp 2009-03-19 20:03:05 UTC (rev 488)
@@ -54,10 +54,10 @@
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);
- asprintf(&m_archives_path, "%s/Archives", m_depot_path);
+ 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);
@@ -66,7 +66,7 @@
res = this->lock(LOCK_SH);
if (res == 0) {
- m_is_locked = 1;
+ m_is_locked = 1;
}
int exists = is_regular_file(m_database_path);
@@ -292,7 +292,7 @@
// and the file that actually exists in this location (actual).
char* actpath;
- asprintf(&actpath, "%s/%s", this->prefix(), file->path());
+ join_path(&actpath, this->prefix(), file->path());
File* actual = FileFactory(actpath);
File* preceding = this->file_preceded_by(file);
@@ -375,10 +375,13 @@
const char* dir = dirname(path);
assert(dir != NULL);
+ char *uuidpath;
char uuidstr[37];
uuid_unparse_upper(rollback->uuid(), uuidstr);
- asprintf(&backup_dirpath, "%s/%s/%s", m_archives_path, uuidstr, dir);
+ asprintf(&uuidpath, "%s/%s", m_archives_path, uuidstr);
+ assert(uuidpath != NULL);
+ join_path(&backup_dirpath, uuidpath, dir);
assert(backup_dirpath != NULL);
res = mkdir_p(backup_dirpath);
@@ -388,6 +391,7 @@
res = 0;
}
free(backup_dirpath);
+ free(uuidpath);
}
@@ -441,7 +445,7 @@
int res = 0;
if (INFO_TEST(file->info(), FILE_INFO_ROLLBACK_DATA)) {
- char *dstpath, *relpath;
+ char *dstpath, *relpath, *uuidpath;
char uuidstr[37];
// we need the path minus our destination path for moving to the archive
relpath = strstr(file->path(), context->depot->m_prefix);
@@ -449,9 +453,10 @@
// advance to just past the destination path
relpath += strlen(context->depot->m_prefix);
}
- uuid_unparse_upper(context->archive->uuid(), uuidstr);
- asprintf(&dstpath, "%s/%s/%s", context->depot->m_archives_path,
- uuidstr, (relpath ? relpath : file->path()));
+ 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()));
assert(dstpath != NULL);
++context->files_modified;
@@ -488,6 +493,7 @@
if (res != 0) fprintf(stderr, "%s:%d: backup failed: %s: %s (%d)\n", __FILE__, __LINE__, dstpath, strerror(errno), errno);
free(dstpath);
+ free(uuidpath);
}
return res;
}
@@ -660,7 +666,7 @@
}
char* actpath;
- asprintf(&actpath, "%s/%s", context->depot->m_prefix, file->path());
+ join_path(&actpath, context->depot->m_prefix, file->path());
IF_DEBUG("[uninstall] actual path is %s\n", actpath);
File* actual = FileFactory(actpath);
uint32_t flags = File::compare(file, actual);
Modified: branches/PR-6688645/darwinup/File.cpp
===================================================================
--- branches/PR-6688645/darwinup/File.cpp 2009-03-19 01:44:32 UTC (rev 487)
+++ branches/PR-6688645/darwinup/File.cpp 2009-03-19 20:03:05 UTC (rev 488)
@@ -142,7 +142,7 @@
char srcpath[PATH_MAX];
const char* path = this->path();
char* dstpath;
- asprintf(&dstpath, "%s/%s", dest, path);
+ join_path(&dstpath, dest, path);
if (dirpath) {
ssize_t len = snprintf(srcpath, sizeof(srcpath), "%s/%s", dirpath, path);
@@ -194,7 +194,7 @@
int File::install_info(const char* dest) {
int res = 0;
char* path;
- asprintf(&path, "%s/%s", dest, this->path());
+ join_path(&path, dest, this->path());
uid_t uid = this->uid();
gid_t gid = this->gid();
mode_t mode = this->mode() & ALLPERMS;
@@ -288,7 +288,7 @@
int res = 0;
char* dstpath;
- asprintf(&dstpath, "%s/%s", dest, this->path());
+ join_path(&dstpath, dest, this->path());
mode_t mode = this->mode() & ALLPERMS;
uid_t uid = this->uid();
Modified: branches/PR-6688645/darwinup/Utils.cpp
===================================================================
--- branches/PR-6688645/darwinup/Utils.cpp 2009-03-19 01:44:32 UTC (rev 487)
+++ branches/PR-6688645/darwinup/Utils.cpp 2009-03-19 20:03:05 UTC (rev 488)
@@ -141,3 +141,59 @@
}
return res;
}
+
+/**
+ * join_path joins two paths and removes any extra slashes,
+ * even internal ones in p1 or p2. It allocates memory
+ * for the string and the caller is responsible for freeing.
+ */
+int join_path(char **out, const char *p1, const char *p2) {
+ int res = 0;
+
+ asprintf(out, "%s/%s", p1, p2);
+ if (!out) {
+ fprintf(stderr, "Error: join_path is out of memory!\n");
+ return -1;
+ }
+
+ int slashes = 0;
+ char *cur = *out;
+ while (*cur != '\0') {
+ if (*cur == '/') {
+ slashes++;
+ } else {
+ // we found the next non-slash
+ if (slashes > 1) {
+ res = compact_slashes(cur, slashes);
+ if (res == -1) {
+ fprintf(stderr, "Error: could not compact slashes\n");
+ return res;
+ }
+ }
+ slashes = 0;
+ }
+ cur++;
+ }
+
+ return 0;
+}
+
+/**
+ * compact_slashes takes a pointer to the next non-slash
+ * after a number of slashes, and shifts characters to the
+ * left in order to overwrite the extra slashes. It also
+ * moves the null terminator.
+ */
+int compact_slashes(char *orig, int slashes) {
+ char *right = orig;
+ char *left = orig - slashes + 1; // leave 1 slash
+
+ while (*right != '\0') {
+ *(left++) = *(right++);
+ }
+
+ // one last assignment to set the new null terminator
+ *left = *right;
+
+ return 0;
+}
Modified: branches/PR-6688645/darwinup/Utils.h
===================================================================
--- branches/PR-6688645/darwinup/Utils.h 2009-03-19 01:44:32 UTC (rev 487)
+++ branches/PR-6688645/darwinup/Utils.h 2009-03-19 20:03:05 UTC (rev 488)
@@ -42,6 +42,9 @@
int has_suffix(const char* str, const char* sfx);
int exec_with_args(const char** args);
+int join_path(char** out, const char* p1, const char* p2);
+int compact_slashes(char* orig, int slashes);
+
inline int INFO_TEST(uint32_t word, uint32_t flag) { return ((word & flag) != 0); }
inline int INFO_SET(uint32_t word, uint32_t flag) { return (word | flag); }
inline int INFO_CLR(uint32_t word, uint32_t flag) { return (word & (~flag)); }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20090319/78a0c98f/attachment.html>
More information about the darwinbuild-changes
mailing list