diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-05-08 22:32:59 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-05-08 22:32:59 -0700 |
commit | 3ecaa3b6a5f707617ea610d727c696f43f8b2f0b (patch) | |
tree | 092dc9814e12b70ae637c26e36e5d0e6813657b4 /wrapper.c | |
parent | 43acff34b902c38808ac0f326090f2516250e1f0 (diff) | |
parent | 25755e842f814751fbdb7abfc8255a40f24bfaa3 (diff) | |
download | git-3ecaa3b6a5f707617ea610d727c696f43f8b2f0b.tar.gz |
Merge branch 'pc/remove-warn'
* pc/remove-warn:
Remove a redundant errno test in a usage of remove_path
Introduce remove_or_warn function
Implement the rmdir_or_warn function
Generalise the unlink_or_warn function
Diffstat (limited to 'wrapper.c')
-rw-r--r-- | wrapper.c | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -311,18 +311,30 @@ int odb_pack_keep(char *name, size_t namesz, unsigned char *sha1) return open(name, O_RDWR|O_CREAT|O_EXCL, 0600); } -int unlink_or_warn(const char *file) +static int warn_if_unremovable(const char *op, const char *file, int rc) { - int rc = unlink(file); - if (rc < 0) { int err = errno; if (ENOENT != err) { - warning("unable to unlink %s: %s", - file, strerror(errno)); + warning("unable to %s %s: %s", + op, file, strerror(errno)); errno = err; } } return rc; } +int unlink_or_warn(const char *file) +{ + return warn_if_unremovable("unlink", file, unlink(file)); +} + +int rmdir_or_warn(const char *file) +{ + return warn_if_unremovable("rmdir", file, rmdir(file)); +} + +int remove_or_warn(unsigned int mode, const char *file) +{ + return S_ISGITLINK(mode) ? rmdir_or_warn(file) : unlink_or_warn(file); +} |