From 7c81201d28a0c4a52f0fb1523e172fedf63f953b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 7 Jan 2009 02:26:34 +0000 Subject: [PATCH] Fix lack of error logging in some situations and fix failure to work on windows when swig is a pure Win32 (non-cygwin) compile git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11034 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CCache/ccache.c | 12 ++++++++---- CCache/util.c | 26 ++++++++++++++++---------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/CCache/ccache.c b/CCache/ccache.c index e35778147..0de4e4136 100644 --- a/CCache/ccache.c +++ b/CCache/ccache.c @@ -329,6 +329,9 @@ static void to_cache(ARGS *args) while (fgets(out_filename, FILENAME_MAX, file)) { char *linefeed = strchr(out_filename, '\n'); if (linefeed) { + char *potential_cr = linefeed - 1; + if (potential_cr >= out_filename && *potential_cr == '\r') + *potential_cr = 0; *linefeed = 0; if (cached_files_count == 0) { @@ -337,8 +340,7 @@ static void to_cache(ARGS *args) sprintf(out_filename_cache, "%s.%d", hashname, cached_files_count); } - if (stat(out_filename, &st1) != 0 || - commit_to_cache(out_filename, out_filename_cache, hardlink) != 0) { + if (commit_to_cache(out_filename, out_filename_cache, hardlink) != 0) { fclose(file); unlink(tmp_outfiles); failed(); @@ -374,8 +376,7 @@ static void to_cache(ARGS *args) failed(); } } else { - if (stat(output_file, &st1) != 0 || - commit_to_cache(output_file, hashname, hardlink) != 0) { + if (commit_to_cache(output_file, hashname, hardlink) != 0) { failed(); } to_cache_stats_helper(&st1, hashname, 0, &files_size, &cached_files_count); @@ -670,6 +671,9 @@ static void from_cache(int first) while (fgets(out_filename, FILENAME_MAX, file)) { char *linefeed = strchr(out_filename, '\n'); if (linefeed) { + char *potential_cr = linefeed - 1; + if (potential_cr >= out_filename && *potential_cr == '\r') + *potential_cr = 0; *linefeed = 0; if (retrieved_files_count == 0) { diff --git a/CCache/util.c b/CCache/util.c index f09256dfc..bba232492 100644 --- a/CCache/util.c +++ b/CCache/util.c @@ -349,20 +349,26 @@ int test_if_compressed(const char *filename) { int commit_to_cache(const char *src, const char *dest, int hardlink) { int ret = -1; - unlink(dest); - if (hardlink) { + struct stat st; + if (stat(src, &st) == 0) { + unlink(dest); + if (hardlink) { #ifdef _WIN32 - ret = CreateHardLinkA(dest, src, NULL) ? 0 : -1; + ret = CreateHardLinkA(dest, src, NULL) ? 0 : -1; #else - ret = link(src, dest); + ret = link(src, dest); #endif - } - if (ret == -1) { - ret = copy_file_to_cache(src, dest); - if (ret == -1) { - cc_log("failed to commit %s -> %s (%s)\n", src, dest, strerror(errno)); - stats_update(STATS_ERROR); } + if (ret == -1) { + ret = copy_file_to_cache(src, dest); + if (ret == -1) { + cc_log("failed to commit %s -> %s (%s)\n", src, dest, strerror(errno)); + stats_update(STATS_ERROR); + } + } + } else { + cc_log("failed to put %s in the cache (%s)\n", src, strerror(errno)); + stats_update(STATS_ERROR); } return ret; }