[darwinbuild-changes] [81] trunk/darwinbuild
source_changes at macosforge.org
source_changes at macosforge.org
Wed Oct 4 01:43:21 PDT 2006
Revision: 81
http://trac.macosforge.org/projects/darwinbuild/changeset/81
Author: kevin
Date: 2006-10-04 01:43:21 -0700 (Wed, 04 Oct 2006)
Log Message:
-----------
- added new manifest tool
Modified Paths:
--------------
trunk/darwinbuild/Makefile
Added Paths:
-----------
trunk/darwinbuild/manifest.c
Modified: trunk/darwinbuild/Makefile
===================================================================
--- trunk/darwinbuild/Makefile 2005-07-13 23:45:18 UTC (rev 80)
+++ trunk/darwinbuild/Makefile 2006-10-04 08:43:21 UTC (rev 81)
@@ -5,8 +5,11 @@
###
DATDIR:=$(DATDIR)/darwinbuild
-all:
+all: manifest
+manifest: manifest.c
+ cc -o $@ -lcrypto $^
+
install: all
[ -d $(BINDIR) ] || $(INSTALL) -d $(INSTALL_DIR_FLAGS) $(BINDIR)
$(INSTALL) $(INSTALL_EXE_FLAGS) darwinbuild $(BINDIR)
@@ -14,6 +17,7 @@
[ -d $(DATDIR) ] || $(INSTALL) -d $(INSTALL_DIR_FLAGS) $(DATDIR)
$(INSTALL) $(INSTALL_DOC_FLAGS) darwinbuild.common $(DATDIR)
+ $(INSTALL) $(INSTALL_EXE_FLAGS) manifest $(DATDIR)
uninstall:
rm -f $(BINDIR)/darwinbuild
Added: trunk/darwinbuild/manifest.c
===================================================================
--- trunk/darwinbuild/manifest.c (rev 0)
+++ trunk/darwinbuild/manifest.c 2006-10-04 08:43:21 UTC (rev 81)
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_BSD_LICENSE_HEADER_START@
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @APPLE_BSD_LICENSE_HEADER_END@
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <fts.h>
+#include <libgen.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <openssl/evp.h>
+
+
+static char* format_digest(const unsigned char* m) {
+ char* result = NULL;
+ // SHA-1
+ asprintf(&result,
+ "%02x%02x%02x%02x"
+ "%02x%02x%02x%02x"
+ "%02x%02x%02x%02x"
+ "%02x%02x%02x%02x"
+ "%02x%02x%02x%02x",
+ m[0], m[1], m[2], m[3],
+ m[4], m[5], m[6], m[7],
+ m[8], m[9], m[10], m[11],
+ m[12], m[13], m[14], m[15],
+ m[16], m[17], m[18], m[19]
+ );
+ return result;
+}
+
+static char* calculate_digest(FTSENT* ent) {
+ unsigned char digstr[EVP_MAX_MD_SIZE];
+ memset(digstr, 0, sizeof(digstr));
+ if (ent->fts_info == FTS_D) return format_digest(digstr);
+
+ EVP_MD_CTX ctx;
+ static const EVP_MD* md;
+
+ if (md == NULL) {
+ EVP_MD_CTX_init(&ctx);
+ OpenSSL_add_all_digests();
+ md = EVP_get_digestbyname("sha1");
+ if (md == NULL) return NULL;
+ }
+
+ EVP_DigestInit(&ctx, md);
+
+ int fd = open(ent->fts_accpath, O_RDONLY, 0);
+ if (fd == -1) return NULL;
+ unsigned int len;
+ const unsigned int blocklen = 8192;
+ static unsigned char* block = NULL;
+ if (block == NULL) {
+ block = malloc(blocklen);
+ }
+ while(1) {
+ len = read(fd, block, blocklen);
+ if (len == 0) { close(fd); break; }
+ if ((len < 0) && (errno == EINTR)) continue;
+ if (len < 0) { close(fd); return NULL; }
+ EVP_DigestUpdate(&ctx, block, len);
+ }
+
+ EVP_DigestFinal(&ctx, digstr, &len);
+ return format_digest(digstr);
+}
+
+static int compare(const FTSENT **a, const FTSENT **b) {
+ return strcmp((*a)->fts_name, (*b)->fts_name);
+}
+
+static void ent_filename(FTSENT* ent, char* filename) {
+ if (ent->fts_level > 1) {
+ ent_filename(ent->fts_parent, filename);
+ strcat(filename, "/");
+ } else if (ent->fts_level == 1) {
+ strcat(filename, "./");
+ }
+ strcat(filename, ent->fts_name);
+}
+
+int main(int argc, char* argv[]) {
+ if (argc != 2) {
+ char* progname = basename(argv[0]);
+ fprintf(stderr, "usage: %s <dir>\n", progname);
+ return 1;
+ }
+ char* path[] = { argv[1], NULL };
+ FTS* fts = fts_open(path, FTS_PHYSICAL | FTS_COMFOLLOW, compare);
+ FTSENT* ent = fts_read(fts); // throw away the entry for the directory itself
+ while ((ent = fts_read(fts)) != NULL) {
+ char filename[MAXPATHLEN];
+ char symlink[MAXPATHLEN+1];
+ int len;
+ off_t size;
+ char* checksum = NULL;
+ symlink[0] = 0;
+ switch (ent->fts_info) {
+ case FTS_SL:
+ case FTS_SLNONE:
+ len = readlink(ent->fts_accpath, symlink, MAXPATHLEN);
+ if (len >= 0) symlink[len] = 0;
+ case FTS_D:
+ checksum = strdup(" ");
+ case FTS_DEFAULT:
+ case FTS_F:
+ if (!checksum) checksum = calculate_digest(ent);
+ filename[0] = 0;
+ ent_filename(ent, filename);
+ fprintf(stdout, "%s %o %d %d %lld %s%s%s\n",
+ checksum,
+ ent->fts_statp->st_mode,
+ ent->fts_statp->st_uid,
+ ent->fts_statp->st_gid,
+ (ent->fts_info != FTS_D) ? ent->fts_statp->st_size : (off_t)0,
+ filename,
+ symlink[0] ? " -> " : "",
+ symlink[0] ? symlink : "");
+ break;
+ }
+ }
+ fts_close(fts);
+}
\ No newline at end of file
Property changes on: trunk/darwinbuild/manifest.c
___________________________________________________________________
Name: svn:eol-style
+ native
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20061004/b3168240/attachment-0001.html
More information about the darwinbuild-changes
mailing list