failed();
}
-#if ENABLE_ZLIB
/* do an extra stat on the cache files for
the size statistics */
if (stat(path_stderr, &st1) != 0 ||
stats_update(STATS_ERROR);
failed();
}
-#endif
cc_log("Placed object file into the cache\n");
stats_tocache(file_size(&st1) + file_size(&st2));
}
/* the user might be disabling cache hits */
- if ((mode != FROMCACHE_COMPILED_MODE && getenv("CCACHE_RECACHE"))
-#ifndef ENABLE_ZLIB
- /* if the cache file is compressed we must recache */
- || test_if_compressed(object_path)
-#endif
- ) {
+ if (mode != FROMCACHE_COMPILED_MODE && getenv("CCACHE_RECACHE")) {
close(fd_stderr);
unlink(stderr_file);
unlink(object_path);
fi
dnl Check for zlib.
-AC_DEFINE([ENABLE_ZLIB], [], [Define to 1 if you have zlib])
-AC_ARG_ENABLE([zlib],
- AS_HELP_STRING([--enable-zlib], [enable zlib support for ccache compression]),,
- [enable_zlib=yes])
-
-if test x"$enable_zlib" = x"yes"; then
- AC_CHECK_HEADER(zlib.h, AC_CHECK_LIB(z, gzdopen, LIBS="-lz $LIBS"; AC_DEFINE(ENABLE_ZLIB)))
-fi
+AC_CHECK_HEADER(
+ zlib.h,
+ AC_CHECK_LIB(
+ z,
+ gzdopen,
+ LIBS="-lz $LIBS",
+ AC_MSG_ERROR(Required library zlib missing.)),
+ AC_MSG_ERROR(Header file for required library zlib missing.))
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
exit(1);
}
-#ifndef ENABLE_ZLIB
-/* copy all data from one file descriptor to another */
-void copy_fd(int fd_in, int fd_out)
-{
- char buf[10240];
- int n;
-
- while ((n = read(fd_in, buf, sizeof(buf))) > 0) {
- if (write(fd_out, buf, n) != n) {
- fatal("Failed to copy fd\n");
- }
- }
-}
-
-static int safe_rename(const char* oldpath, const char* newpath)
-{
- /* safe_rename is for creating entries in the cache.
-
- Works like rename(), but it never overwrites an existing
- cache entry. This avoids corruption on NFS. */
- int status = link(oldpath, newpath);
- if (status == 0 || errno == EEXIST) {
- return unlink(oldpath);
- }
- else {
- return -1;
- }
-}
-
-/* move a file using rename */
-int move_file(const char *src, const char *dest) {
- return safe_rename(src, dest);
-}
-
-/* copy a file - used when hard links don't work
- the copy is done via a temporary file and atomic rename
-*/
-int copy_file(const char *src, const char *dest)
-{
- int fd1, fd2;
- char buf[10240];
- int n;
- char *tmp_name;
- mode_t mask;
-
- x_asprintf(&tmp_name, "%s.XXXXXX", dest);
-
- fd1 = open(src, O_RDONLY|O_BINARY);
- if (fd1 == -1) {
- free(tmp_name);
- return -1;
- }
-
- fd2 = mkstemp(tmp_name);
- if (fd2 == -1) {
- close(fd1);
- free(tmp_name);
- return -1;
- }
-
- while ((n = read(fd1, buf, sizeof(buf))) > 0) {
- if (write(fd2, buf, n) != n) {
- close(fd2);
- close(fd1);
- unlink(tmp_name);
- free(tmp_name);
- return -1;
- }
- }
-
- close(fd1);
-
- /* get perms right on the tmp file */
- mask = umask(0);
- fchmod(fd2, 0666 & ~mask);
- umask(mask);
-
- /* the close can fail on NFS if out of space */
- if (close(fd2) == -1) {
- unlink(tmp_name);
- free(tmp_name);
- return -1;
- }
-
- unlink(dest);
-
- if (rename(tmp_name, dest) == -1) {
- unlink(tmp_name);
- free(tmp_name);
- return -1;
- }
-
- free(tmp_name);
-
- return 0;
-}
-
-#else /* ENABLE_ZLIB */
-
/* copy all data from one file descriptor to another
possibly decompressing it
*/
int copy_file(const char *src, const char *dest) {
return _copy_file(src, dest, COPY_FROM_CACHE);
}
-#endif /* ENABLE_ZLIB */
/* test if a file is zlib compressed */
int test_if_compressed(const char *filename) {