All of lore.kernel.org
 help / color / mirror / Atom feed
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 v2 05/26] copy.c: convert bb_(p)error_msg to (sys_)error
Date: Tue, 16 Feb 2016 20:29:06 +0700	[thread overview]
Message-ID: <1455629367-26193-6-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1455629367-26193-1-git-send-email-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 d24a8ae..cdb38d5 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 sys_error(_("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 sys_error(_("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 sys_error(_("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 sys_error(_("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);
+			sys_error(_("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 sys_error(_("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 = sys_error(_("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 sys_error(_("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);
+				sys_error(_("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 sys_error(_("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);
+			sys_error(_("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);
+			sys_error(_("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);
+			sys_error(_("can't preserve %s of '%s'"), "permissions", dest);
 	}
 
 	return retval;
-- 
2.7.0.377.g4cd97dd

  parent reply	other threads:[~2016-02-16 13:29 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-03  9:35 [PATCH 00/20] "git worktree move" preview Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 01/20] usage.c: move format processing out of die_errno() Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 02/20] usage.c: add sys_error() that prints strerror() automatically Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 03/20] path.c: add git_common_path() and strbuf_git_common_path() Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 04/20] path.c: add is_git_path_shared() Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 05/20] copy.c: add copy_dir_recursively() Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 06/20] worktree.c: use is_dot_or_dotdot() Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 07/20] worktree.c: store "id" instead of "git_dir" Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 08/20] worktree.c: add clear_worktree() Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 09/20] worktree.c: add find_worktree_by_path() Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 10/20] worktree.c: add is_main_worktree() Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 11/20] worktree.c: recognize no main worktree Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 12/20] worktree.c: add update_worktree_location() Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 13/20] worktree.c: add update_worktree_gitfile() Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 14/20] worktree.c: add collect_per_worktree_git_paths() Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 15/20] worktree: avoid 0{40}, too many zeroes, hard to read Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 16/20] worktree: simplify prefixing paths Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 17/20] worktree: add "move" commmand Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 18/20] worktree: refactor add_worktree() Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 19/20] worktree: move repo, simple case Nguyễn Thái Ngọc Duy
2016-02-03  9:35 ` [PATCH 20/20] worktree: move repo, convert main worktree Nguyễn Thái Ngọc Duy
2016-02-16 13:29 ` [PATCH v2 00/26] worktree lock, move, remove and unlock Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 01/26] usage.c: move format processing out of die_errno() Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 02/26] usage.c: add sys_error() that prints strerror() automatically Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 03/26] copy.c: import copy_file() from busybox Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 04/26] copy.c: delete unused code in copy_file() Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` Nguyễn Thái Ngọc Duy [this message]
2016-02-16 13:29   ` [PATCH v2 06/26] copy.c: style fix Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 07/26] copy.c: convert copy_file() to copy_dir_recursively() Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 08/26] completion: support git-worktree Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 09/26] git-worktree.txt: keep subcommand listing in alphabetical order Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 10/26] wrapper.c: allow to create an empty file with write_file() Nguyễn Thái Ngọc Duy
2016-02-17 22:29     ` Junio C Hamano
2016-02-18  0:49       ` Duy Nguyen
2016-02-16 13:29   ` [PATCH v2 11/26] path.c: add git_common_path() and strbuf_git_common_path() Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 12/26] worktree.c: use is_dot_or_dotdot() Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 13/26] worktree.c: store "id" instead of "git_dir" Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 14/26] worktree.c: add clear_worktree() Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 15/26] worktree.c: add find_worktree_by_path() Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 16/26] worktree.c: add is_main_worktree() Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 17/26] worktree.c: add validate_worktree() Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 18/26] worktree.c: add update_worktree_location() Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 19/26] worktree.c: add is_worktree_locked() Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 20/26] worktree: avoid 0{40}, too many zeroes, hard to read Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 21/26] worktree: simplify prefixing paths Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 22/26] worktree: add "lock" command Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 23/26] worktree: add "unlock" command Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 24/26] worktree: add "move" commmand Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 25/26] worktree move: accept destination as directory Nguyễn Thái Ngọc Duy
2016-02-16 13:29   ` [PATCH v2 26/26] worktree: add "remove" command Nguyễn Thái Ngọc Duy

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=1455629367-26193-6-git-send-email-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.