]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Merge maint into master (using imerge)
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 13 Nov 2014 21:35:21 +0000 (22:35 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 13 Nov 2014 21:35:21 +0000 (22:35 +0100)
1  2 
ccache.c
ccache.h
lockfile.c
manifest.c
stats.c
util.c

diff --cc ccache.c
index 0b05d1b9ca35d3128e5570d6c68f3ba555791c00,7b9fd0b0435b6dc5e46c90c22f61b3df420f3b7c..dcdb3f430b2ccc98c5c9b5871a435f9e082bef37
+++ b/ccache.c
@@@ -732,27 -606,21 +732,29 @@@ get_file_from_cache(const char *source
  static void
  to_cache(struct args *args)
  {
 -      char *tmp_stdout, *tmp_stderr, *tmp_obj;
 +      char *tmp_stdout, *tmp_stderr, *tmp_dia;
        struct stat st;
        int status;
 -      size_t added_bytes = 0;
 -      unsigned added_files = 0;
  
 +      if (create_parent_dirs(cached_obj) != 0) {
 +              fatal("Failed to create parent directory for %s: %s",
 +                    cached_obj, strerror(errno));
 +      }
        tmp_stdout = format("%s.tmp.stdout.%s", cached_obj, tmp_string());
+       create_empty_file(tmp_stdout);
        tmp_stderr = format("%s.tmp.stderr.%s", cached_obj, tmp_string());
 -      tmp_obj = format("%s.tmp.%s", cached_obj, tmp_string());
 -      create_empty_file(tmp_obj);
+       create_empty_file(tmp_stderr);
  
        args_add(args, "-o");
 -      args_add(args, tmp_obj);
 +      args_add(args, output_obj);
 +
 +      if (output_dia) {
 +              tmp_dia = x_strdup(output_dia);
 +              args_add(args, "--serialize-diagnostics");
 +              args_add(args, tmp_dia);
 +      } else {
 +              tmp_dia = NULL;
 +      }
  
        /* Turn off DEPENDENCIES_OUTPUT when running cc1, because
         * otherwise it will emit a line like
@@@ -972,22 -810,24 +974,28 @@@ get_object_name_from_cpp(struct args *a
                input_base[10] = 0;
        }
  
-       path_stdout = format(
-               "%s/%s.tmp.%s.%s",
-               temp_dir(), input_base, tmp_string(), conf->cpp_extension);
 -      path_stderr = format("%s/tmp.cpp_stderr.%s", temp_dir, tmp_string());
 +      path_stderr = format("%s/tmp.cpp_stderr.%s", temp_dir(), tmp_string());
-       if (create_parent_dirs(path_stdout) != 0) {
++      if (create_parent_dirs(path_stderr) != 0) {
 +              fatal("Failed to create parent directory for %s: %s\n",
-                     path_stdout, strerror(errno));
++                    path_stderr, strerror(errno));
 +      }
-       add_pending_tmp_file(path_stdout);
+       create_empty_file(path_stderr);
        add_pending_tmp_file(path_stderr);
  
        time_of_compilation = time(NULL);
  
        if (!direct_i_file) {
 -                      format("%s/%s.tmp.%s", temp_dir, input_base, tmp_string());
+               /* The temporary file needs the proper i_extension for the compiler to do
+                * its thing. However, create_empty_file requires the tmp_string() part to
+                * be last, which is why the temporary file is created in two steps. */
+               char *path_stdout_tmp =
 -              path_stdout = format("%s.%s", path_stdout_tmp, i_extension);
++                      format("%s/%s.tmp.%s", temp_dir(), input_base, tmp_string());
+               create_empty_file(path_stdout_tmp);
++              path_stdout = format("%s.%s", path_stdout_tmp, conf->cpp_extension);
+               x_rename(path_stdout_tmp, path_stdout);
+               free(path_stdout_tmp);
+               add_pending_tmp_file(path_stdout);
                /* run cpp on the input file to obtain the .i */
                args_add(args, "-E");
                args_add(args, input_file);
diff --cc ccache.h
index 6f60f1a358f3f07b81dbd897f3d92f74b8e9f04c,adcc381609556f9f496b8f6e67fb190e21f622ef..a98bd94e2ea976cffbc48852ada1e8108c253c67
+++ b/ccache.h
@@@ -142,18 -130,12 +142,17 @@@ char *dirname(const char *path)
  const char *get_extension(const char *path);
  char *remove_extension(const char *path);
  size_t file_size(struct stat *st);
- int safe_create_wronly(const char *fname);
 -int safe_open(const char *fname);
 +char *format_human_readable_size(uint64_t size);
 +char *format_parsable_size_with_suffix(uint64_t size);
 +bool parse_size_with_suffix(const char *str, uint64_t *size);
  char *x_realpath(const char *path);
  char *gnu_getcwd(void);
- int create_empty_file(const char *fname);
 +#ifndef HAVE_STRTOK_R
 +char *strtok_r(char *str, const char *delim, char **saveptr);
 +#endif
+ int create_empty_file(char *fname);
  const char *get_home_directory(void);
 -char *get_cwd();
 +char *get_cwd(void);
  bool same_executable_name(const char *s1, const char *s2);
  size_t common_dir_prefix_length(const char *s1, const char *s2);
  char *get_relative_path(const char *from, const char *to);
diff --cc lockfile.c
Simple merge
diff --cc manifest.c
index b2a85951e513ecec08d651072cac2290bd685d1e,660d437f6e515d1dec82eb235bee1f24dc018f74..4d652eedd868054b835a20cb9eaf3734ae0d3f9f
@@@ -737,7 -653,7 +737,13 @@@ manifest_put(const char *manifest_path
        }
  
        tmp_file = format("%s.tmp.%s", manifest_path, tmp_string());
-       fd2 = safe_create_wronly(tmp_file);
+       fd2 = mkstemp(tmp_file);
++      if (fd2 == -1 && errno == ENOENT) {
++              if (create_parent_dirs(tmp_file) == 0) {
++                      reformat(&tmp_file, "%s.tmp.%s", manifest_path, tmp_string());
++                      fd2 = mkstemp(tmp_file);
++              }
++      }
        if (fd2 == -1) {
                cc_log("Failed to open %s", tmp_file);
                goto out;
diff --cc stats.c
index 5754db7acafbc33854b9c60a445b3c1d3fcfebd4,6a3c977e109e741e6af1fb3c9e293b3e174bf5a6..16aaa9fe312438812a7a2f6700a78ad30a456947
+++ b/stats.c
@@@ -130,14 -126,15 +130,22 @@@ stats_write(const char *path, struct co
        size_t i;
        char *tmp_file;
        FILE *f;
+       int fd;
  
        tmp_file = format("%s.tmp.%s", path, tmp_string());
-       f = fopen(tmp_file, "wb");
-       if (!f && errno == ENOENT) {
-               if (create_parent_dirs(path) == 0) {
-                       f = fopen(tmp_file, "wb");
+       fd = mkstemp(tmp_file);
++      if (fd == -1 && errno == ENOENT) {
++              if (create_parent_dirs(tmp_file) == 0) {
++                      reformat(&tmp_file, "%s.tmp.%s", path, tmp_string());
++                      fd = mkstemp(tmp_file);
 +              }
 +      }
+       if (fd == -1) {
+               cc_log("Failed to open %s", tmp_file);
++              close(fd);
+               goto end;
+       }
+       f = fdopen(fd, "wb");
        if (!f) {
                cc_log("Failed to open %s", tmp_file);
                goto end;
@@@ -360,7 -353,13 +368,13 @@@ stats_zero(void
  
        for (dir = 0; dir <= 0xF; dir++) {
                struct counters *counters = counters_init(STATS_END);
 -              fname = format("%s/%1x/stats", cache_dir, dir);
+               struct stat st;
 +              fname = format("%s/%1x/stats", conf->cache_dir, dir);
+               if (stat(fname, &st) != 0) {
+                       /* No point in trying to reset the stats file if it doesn't exist. */
+                       free(fname);
+                       continue;
+               }
                if (lockfile_acquire(fname, lock_staleness_limit)) {
                        stats_read(fname, counters);
                        for (i = 0; stats_info[i].message; i++) {
diff --cc util.c
index 156c0bead0be935f05920d7543a938c5bc464ba4,4c18e1576b20f78eab6c3f198e7cf7f191a3276e..8dbf01a454fadd4dd4b2350e0862062dd4775ee1
--- 1/util.c
--- 2/util.c
+++ b/util.c
@@@ -241,17 -195,9 +241,17 @@@ copy_file(const char *src, const char *
        struct stat st;
        int errnum;
  
-       tmp_name = format("%s.%s.XXXXXX", dest, tmp_string());
+       tmp_name = format("%s.%s", dest, tmp_string());
 -      cc_log("Copying %s to %s via %s (%s)",
 -             src, dest, tmp_name, compress_dest ? "compressed": "uncompressed");
 +
 +      /* open destination file */
 +      fd_out = mkstemp(tmp_name);
 +      if (fd_out == -1) {
 +              cc_log("mkstemp error: %s", strerror(errno));
 +              goto error;
 +      }
 +
 +      cc_log("Copying %s to %s via %s (%scompressed)",
 +             src, dest, tmp_name, compress_level > 0 ? "" : "un");
  
        /* open source file */
        fd_in = open(src, O_RDONLY | O_BINARY);
@@@ -854,53 -751,31 +854,34 @@@ file_size(struct stat *st
  #endif
  }
  
- /*
-  * Create a file for writing. Creates parent directories if they don't exist.
-  */
 -/* a safe open/create for read-write */
--int
- safe_create_wronly(const char *fname)
- {
-       int fd = open(fname, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0666);
-       if (fd == -1 && errno == ENOENT) {
-               /*
-                * Only make sure parent directories exist when have failed to open the
-                * file -- this saves stat() calls.
-                */
-               if (create_parent_dirs(fname) == 0) {
-                       fd = open(fname, O_RDWR | O_CREAT | O_EXCL | O_BINARY, 0666);
-               }
-       }
-       return fd;
- }
 -safe_open(const char *fname)
 +/* Format a size as a human-readable string. Caller frees. */
 +char *
 +format_human_readable_size(uint64_t v)
  {
 -      int fd = open(fname, O_RDWR|O_BINARY);
 -      if (fd == -1 && errno == ENOENT) {
 -              fd = open(fname, O_RDWR|O_CREAT|O_EXCL|O_BINARY, 0666);
 -              if (fd == -1 && errno == EEXIST) {
 -                      fd = open(fname, O_RDWR|O_BINARY);
 -              }
 +      char *s;
 +      if (v >= 1000*1000*1000) {
 +              s = format("%.1f GB", v/((double)(1000*1000*1000)));
 +      } else if (v >= 1000*1000) {
 +              s = format("%.1f MB", v/((double)(1000*1000)));
 +      } else {
 +              s = format("%.1f kB", v/((double)(1000)));
        }
 -      return fd;
 +      return s;
  }
  
 -/* Format a size (in KiB) as a human-readable string. Caller frees. */
 +/* Format a size as a parsable string. Caller frees. */
  char *
 -format_size(size_t v)
 +format_parsable_size_with_suffix(uint64_t size)
  {
        char *s;
 -      if (v >= 1024*1024) {
 -              s = format("%.1f Gbytes", v/((double)(1024*1024)));
 -      } else if (v >= 1024) {
 -              s = format("%.1f Mbytes", v/((double)(1024)));
 +      if (size >= 1000*1000*1000) {
 +              s = format("%.1fG", size / ((double)(1000*1000*1000)));
 +      } else if (size >= 1000*1000) {
 +              s = format("%.1fM", size / ((double)(1000*1000)));
 +      } else if (size >= 1000) {
 +              s = format("%.1fk", size / ((double)(1000)));
        } else {
 -              s = format("%.0f Kbytes", (double)v);
 +              s = format("%u", (unsigned)size);
        }
        return s;
  }
@@@ -1019,31 -884,9 +1000,31 @@@ gnu_getcwd(void
        }
  }
  
 +#ifndef HAVE_STRTOK_R
 +/* strtok_r replacement */
 +char *
 +strtok_r(char *str, const char *delim, char **saveptr)
 +{
 +      int len;
 +      char *ret;
 +      if (!str)
 +              str = *saveptr;
 +      len = strlen(str);
 +      ret = strtok(str, delim);
 +      if (ret) {
 +              char *save = ret;
 +              while (*save++);
 +              if ((len + 1) == (intptr_t) (save - str))
 +                      save--;
 +              *saveptr = save;
 +      }
 +      return ret;
 +}
 +#endif
 +
  /* create an empty file */
  int
- create_empty_file(const char *fname)
+ create_empty_file(char *fname)
  {
        int fd;