From 9c375f2970d8d65dfb01c50c9363f2ee61e3d557 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Wed, 11 May 2011 20:42:06 +0000 Subject: [PATCH] Avoid copying identical files --- src/cp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cp.c b/src/cp.c index 23dc9d9..244773b 100644 --- a/src/cp.c +++ b/src/cp.c @@ -1,5 +1,5 @@ /* $Id$ */ -/* Copyright (c) 2009 Pierre Pronchery */ +/* Copyright (c) 2011 Pierre Pronchery */ /* This file is part of DeforaOS Unix utils */ /* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -113,6 +113,12 @@ static int _cp_single(Prefs * prefs, char const * src, char const * dst) return _cp_error(src, 1); if(lstat(dst, &st2) == 0) { + if(st.st_dev == st2.st_dev && st.st_ino == st2.st_ino) + { + fprintf(stderr, "%s: %s: \"%s\"%s\n", "cp", dst, src, + " is identical (not copied)"); + return 0; + } if(*prefs & CP_PREFS_i && _cp_confirm(dst) != 1) return 0; if(unlink(dst) != 0) @@ -232,7 +238,7 @@ static int _cp_single_regular(char const * src, char const * dst) if(fwrite(buf, sizeof(char), size, fdst) != size) break; if(!feof(fsrc)) - ret |= _cp_error(size == 0 ? src : dst, 1); + ret |= _cp_error((size == 0) ? src : dst, 1); if(fclose(fsrc) != 0) ret |= _cp_error(src, 1); if(fclose(fdst) != 0)