mirror of
https://github.com/reactos/ccache.git
synced 2025-01-22 03:16:29 +00:00
Rename temporary object file to cached object file if possible
This avoids copying the object file unnecessarily in the common case when we store object files uncompressed in the cache.
This commit is contained in:
parent
f12d64243f
commit
c609b16cc0
5
ccache.c
5
ccache.c
@ -594,7 +594,8 @@ static void to_cache(ARGS *args)
|
||||
failed();
|
||||
}
|
||||
if (st.st_size > 0) {
|
||||
if (move_file(tmp_stderr, cached_stderr, compress) != 0) {
|
||||
if (move_uncompressed_file(tmp_stderr, cached_stderr,
|
||||
compress) != 0) {
|
||||
cc_log("Failed to move %s to %s",
|
||||
tmp_stderr, cached_stderr);
|
||||
stats_update(STATS_ERROR);
|
||||
@ -604,7 +605,7 @@ static void to_cache(ARGS *args)
|
||||
} else {
|
||||
unlink(tmp_stderr);
|
||||
}
|
||||
if (move_file(tmp_obj, cached_obj, compress) != 0) {
|
||||
if (move_uncompressed_file(tmp_obj, cached_obj, compress) != 0) {
|
||||
cc_log("Failed to move %s to %s", tmp_obj, cached_obj);
|
||||
stats_update(STATS_ERROR);
|
||||
failed();
|
||||
|
2
ccache.h
2
ccache.h
@ -70,6 +70,8 @@ void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
|
||||
void copy_fd(int fd_in, int fd_out);
|
||||
int copy_file(const char *src, const char *dest, int compress_dest);
|
||||
int move_file(const char *src, const char *dest, int compress_dest);
|
||||
int move_uncompressed_file(const char *src, const char *dest,
|
||||
int compress_dest);
|
||||
int test_if_compressed(const char *filename);
|
||||
|
||||
int create_dir(const char *dir);
|
||||
|
14
util.c
14
util.c
@ -259,6 +259,20 @@ int move_file(const char *src, const char *dest, int compress_dest)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Like move_file(), but assumes that src is uncompressed and that src and dest
|
||||
* are on the same file system.
|
||||
*/
|
||||
int
|
||||
move_uncompressed_file(const char *src, const char *dest, int compress_dest)
|
||||
{
|
||||
if (compress_dest) {
|
||||
return move_file(src, dest, compress_dest);
|
||||
} else {
|
||||
return rename(src, dest);
|
||||
}
|
||||
}
|
||||
|
||||
/* test if a file is zlib compressed */
|
||||
int test_if_compressed(const char *filename)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user