mirror of
git://git.suckless.org/sbase
synced 2025-03-19 17:46:01 +00:00
The POSIX spec gives many options on how to handle this case, but it also states that cp (and mv) should continue with remaining operands regardless. We used to exit immediately, which violates the spec. This change makes cp/mv not exit immediately in this case and also won't cause the return value to be non-zero. From `man 1p cp`: If source_file references the same file as dest_file, cp may write a diagnostic message to standard error; it shall do nothing more with source_file and shall go on to any remaining files.
23 lines
456 B
C
23 lines
456 B
C
/* See LICENSE file for copyright and license details. */
|
|
#include <sys/stat.h>
|
|
|
|
#include "../util.h"
|
|
|
|
void
|
|
fnck(const char *a, const char *b,
|
|
int (*fn)(const char *, const char *, int), int depth)
|
|
{
|
|
struct stat sta, stb;
|
|
|
|
if (!stat(a, &sta)
|
|
&& !stat(b, &stb)
|
|
&& sta.st_dev == stb.st_dev
|
|
&& sta.st_ino == stb.st_ino) {
|
|
weprintf("%s -> %s: same file\n", a, b);
|
|
return;
|
|
}
|
|
|
|
if (fn(a, b, depth) < 0)
|
|
eprintf("%s -> %s:", a, b);
|
|
}
|