summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f18ca73)
raw | patch | inline | side by side (parent: f18ca73)
author | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Wed, 20 Apr 2005 16:28:05 +0000 (09:28 -0700) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Wed, 20 Apr 2005 16:28:05 +0000 (09:28 -0700) |
Avoid the compression.
sha1_file.c | patch | blob | history |
diff --git a/sha1_file.c b/sha1_file.c
index 40c00b77d0e52b31dda1696f10026fe6f92bc082..eee3598bb75e2199045b823f007e7933c0fb9cfe 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
z_stream stream;
unsigned char sha1[20];
SHA_CTX c;
+ char *filename;
+ int fd;
/* Sha1.. */
SHA1_Init(&c);
SHA1_Update(&c, buf, len);
SHA1_Final(sha1, &c);
+ if (returnsha1)
+ memcpy(returnsha1, sha1, 20);
+
+ filename = sha1_file_name(sha1);
+ fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0666);
+ if (fd < 0) {
+ if (errno != EEXIST)
+ return -1;
+
+ /*
+ * We might do collision checking here, but we'd need to
+ * uncompress the old file and check it. Later.
+ */
+ return 0;
+ }
+
/* Set it up */
memset(&stream, 0, sizeof(stream));
deflateInit(&stream, Z_BEST_COMPRESSION);
deflateEnd(&stream);
size = stream.total_out;
- if (write_sha1_buffer(sha1, compressed, size) < 0)
- return -1;
- if (returnsha1)
- memcpy(returnsha1, sha1, 20);
+ if (write(fd, compressed, size) != size)
+ die("unable to write file");
+ close(fd);
+
return 0;
}