From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 03/10] copy.c: convert bb_(p)error_msg to error(_errno)
Date: Sat, 25 Jun 2016 09:54:26 +0200 [thread overview]
Message-ID: <20160625075433.4608-4-pclouds@gmail.com> (raw)
In-Reply-To: <20160625075433.4608-1-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
copy.c | 85 ++++++++++++++++++++++++------------------------------------------
1 file changed, 31 insertions(+), 54 deletions(-)
diff --git a/copy.c b/copy.c
index b7a87f1..074b609 100644
--- a/copy.c
+++ b/copy.c
@@ -82,23 +82,16 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
smallint dest_exists = 0;
smallint ovr;
- if (lstat(source, &source_stat) < 0) {
- bb_perror_msg("can't stat '%s'", source);
- return -1;
- }
+ if (lstat(source, &source_stat) < 0)
+ return error_errno(_("can't stat '%s'"), source);
if (lstat(dest, &dest_stat) < 0) {
- if (errno != ENOENT) {
- bb_perror_msg("can't stat '%s'", dest);
- return -1;
- }
+ if (errno != ENOENT)
+ return error_errno(_("can't stat '%s'"), dest);
} else {
- if (source_stat.st_dev == dest_stat.st_dev
- && source_stat.st_ino == dest_stat.st_ino
- ) {
- bb_error_msg("'%s' and '%s' are the same file", source, dest);
- return -1;
- }
+ if (source_stat.st_dev == dest_stat.st_dev &&
+ source_stat.st_ino == dest_stat.st_ino)
+ return error(_("'%s' and '%s' are the same file"), source, dest);
dest_exists = 1;
}
@@ -110,18 +103,14 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
/* Did we ever create source ourself before? */
tp = is_in_ino_dev_hashtable(&source_stat);
- if (tp) {
+ if (tp)
/* We did! it's a recursion! man the lifeboats... */
- bb_error_msg("recursion detected, omitting directory '%s'",
- source);
- return -1;
- }
+ return error(_("recursion detected, omitting directory '%s'"),
+ source);
if (dest_exists) {
- if (!S_ISDIR(dest_stat.st_mode)) {
- bb_error_msg("target '%s' is not a directory", dest);
- return -1;
- }
+ if (!S_ISDIR(dest_stat.st_mode))
+ return error(_("target '%s' is not a directory"), dest);
/* race here: user can substitute a symlink between
* this check and actual creation of files inside dest */
} else {
@@ -134,15 +123,12 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
mode |= S_IRWXU;
if (mkdir(dest, mode) < 0) {
umask(saved_umask);
- bb_perror_msg("can't create directory '%s'", dest);
- return -1;
+ return error_errno(_("can't create directory '%s'"), dest);
}
umask(saved_umask);
/* need stat info for add_to_ino_dev_hashtable */
- if (lstat(dest, &dest_stat) < 0) {
- bb_perror_msg("can't stat '%s'", dest);
- return -1;
- }
+ if (lstat(dest, &dest_stat) < 0)
+ return error_errno(_("can't stat '%s'"), dest);
}
/* remember (dev,inode) of each created dir.
* NULL: name is not remembered */
@@ -172,7 +158,7 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
if (!dest_exists
&& chmod(dest, source_stat.st_mode & ~saved_umask) < 0
) {
- bb_perror_msg("can't preserve %s of '%s'", "permissions", dest);
+ error_errno(_("can't preserve permissions of '%s'"), dest);
/* retval = -1; - WRONG! copy *WAS* made */
}
goto preserve_mode_ugid_time;
@@ -196,10 +182,8 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
ovr = ask_and_unlink(dest, flags);
if (ovr <= 0)
return ovr;
- if (link(link_target, dest) < 0) {
- bb_perror_msg("can't create link '%s'", dest);
- return -1;
- }
+ if (link(link_target, dest) < 0)
+ return error_errno(_("can't create link '%s'"), dest);
}
return 0;
}
@@ -238,10 +222,8 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
if (bb_copyfd_eof(src_fd, dst_fd) == -1)
retval = -1;
/* Careful with writing... */
- if (close(dst_fd) < 0) {
- bb_perror_msg("error writing to '%s'", dest);
- retval = -1;
- }
+ if (close(dst_fd) < 0)
+ retval = error_errno(_("error writing to '%s'"), dest);
/* ...but read size is already checked by bb_copyfd_eof */
close(src_fd);
/* "cp /dev/something new_file" should not
@@ -265,12 +247,10 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
if (lpath) {
int r = symlink(lpath, dest);
free(lpath);
- if (r < 0) {
- bb_perror_msg("can't create symlink '%s'", dest);
- return -1;
- }
+ if (r < 0)
+ return error_errno(_("can't create symlink '%s'"), dest);
if (lchown(dest, source_stat.st_uid, source_stat.st_gid) < 0)
- bb_perror_msg("can't preserve %s of '%s'", "ownership", dest);
+ error_errno(_("can't preserve %s of '%s'"), "ownership", dest);
}
/* _Not_ jumping to preserve_mode_ugid_time:
* symlinks don't have those */
@@ -279,14 +259,11 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
if (S_ISBLK(source_stat.st_mode) || S_ISCHR(source_stat.st_mode)
|| S_ISSOCK(source_stat.st_mode) || S_ISFIFO(source_stat.st_mode)
) {
- if (mknod(dest, source_stat.st_mode, source_stat.st_rdev) < 0) {
- bb_perror_msg("can't create '%s'", dest);
- return -1;
- }
- } else {
- bb_error_msg("unrecognized file '%s' with mode %x", source, source_stat.st_mode);
- return -1;
- }
+ if (mknod(dest, source_stat.st_mode, source_stat.st_rdev) < 0)
+ return error_errno(_("can't create '%s'"), dest);
+ } else
+ return error(_("unrecognized file '%s' with mode %x"),
+ source, source_stat.st_mode);
preserve_mode_ugid_time:
@@ -297,13 +274,13 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
times[1].tv_usec = times[0].tv_usec = 0;
/* BTW, utimes sets usec-precision time - just FYI */
if (utimes(dest, times) < 0)
- bb_perror_msg("can't preserve %s of '%s'", "times", dest);
+ error_errno(_("can't preserve %s of '%s'"), "times", dest);
if (chown(dest, source_stat.st_uid, source_stat.st_gid) < 0) {
source_stat.st_mode &= ~(S_ISUID | S_ISGID);
- bb_perror_msg("can't preserve %s of '%s'", "ownership", dest);
+ error_errno(_("can't preserve %s of '%s'"), "ownership", dest);
}
if (chmod(dest, source_stat.st_mode) < 0)
- bb_perror_msg("can't preserve %s of '%s'", "permissions", dest);
+ error_errno(_("can't preserve %s of '%s'"), "permissions", dest);
}
return retval;
--
2.8.2.526.g02eed6d
next prev parent reply other threads:[~2016-06-25 8:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-25 7:54 [PATCH 00/10] git worktree (re)move Nguyễn Thái Ngọc Duy
2016-06-25 7:54 ` [PATCH 01/10] copy.c: import copy_file() from busybox Nguyễn Thái Ngọc Duy
2016-06-25 7:54 ` [PATCH 02/10] copy.c: delete unused code in copy_file() Nguyễn Thái Ngọc Duy
2016-06-25 7:54 ` Nguyễn Thái Ngọc Duy [this message]
2016-06-25 7:54 ` [PATCH 04/10] copy.c: style fix Nguyễn Thái Ngọc Duy
2016-06-25 7:54 ` [PATCH 05/10] copy.c: convert copy_file() to copy_dir_recursively() Nguyễn Thái Ngọc Duy
2017-08-01 18:23 ` Eric Sunshine
2016-06-25 7:54 ` [PATCH 06/10] worktree.c: add validate_worktree() Nguyễn Thái Ngọc Duy
2016-06-25 7:54 ` [PATCH 07/10] worktree.c: add update_worktree_location() Nguyễn Thái Ngọc Duy
2017-08-01 18:23 ` Eric Sunshine
2016-06-25 7:54 ` [PATCH 08/10] worktree: add "move" commmand Nguyễn Thái Ngọc Duy
2017-08-01 18:23 ` Eric Sunshine
2016-06-25 7:54 ` [PATCH 09/10] worktree move: accept destination as directory Nguyễn Thái Ngọc Duy
2016-06-25 7:54 ` [PATCH 10/10] worktree: add "remove" command Nguyễn Thái Ngọc Duy
2017-08-01 18:24 ` Eric Sunshine
2016-07-23 11:09 ` [PATCH 00/10] git worktree (re)move Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160625075433.4608-4-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.