From patchwork Sun Nov 3 20:26:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11224393 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F32ED15AB for ; Sun, 3 Nov 2019 20:27:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D1CF02190F for ; Sun, 3 Nov 2019 20:27:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kyZcYR5C" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727942AbfKCU1D (ORCPT ); Sun, 3 Nov 2019 15:27:03 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:37203 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727358AbfKCU1C (ORCPT ); Sun, 3 Nov 2019 15:27:02 -0500 Received: by mail-wr1-f65.google.com with SMTP id t1so8852884wrv.4 for ; Sun, 03 Nov 2019 12:27:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:mime-version :content-transfer-encoding:fcc:to:cc; bh=QtPD6aqcB2TUyRJygJP9jevFDJlaBPozvmNdrUNSj04=; b=kyZcYR5Cr6sHVXifpkom56zjk2u0EzFwIADnW+5/3tBLKKkGHdoWK3NUbwbn1Ng9IC q42ss6pY8CJQQDwBhjW7DEVp0WWKlownkQ/Ke6Lb37arQHdsMLoedQMh7saYGFXoymBt I8TKxsQs/aD4CmKeLCmKooPL9sMYklgXx1y/DzTHafMyj+nPUIXbREgNbIwG5OKj4+ol skR1P2IEh7ej0LqE+rA64yqqj+n/W2P1JiP1gZG7AVUIMmkWHfrIwdmkBnGeTRot8SDc n5bz87mEDJ57tupdkeQJxKELoucAdC/69FIwBzo9uuXzhVKyr3hgxUz1TfRWSzqvrqqo MmEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:mime-version:content-transfer-encoding:fcc:to:cc; bh=QtPD6aqcB2TUyRJygJP9jevFDJlaBPozvmNdrUNSj04=; b=CiWMgd4hTqprsimgtH3XLeKoT43dsPKB2v/AHJ6s2yV9tRyDNkIHjge7BIuVuPLo/J ESgkpNzNUmA0FgsAuzIayyj4F3p0EeymmzAKgAMQgBpl+G06GtFx55qeB1H4LQNa8typ 50yXqaJ+wtZKo9A0r5pNQDR51t47NMGkoXpgiMTxZRwo2up2PI/u7ZTISzeRT5efPcqt dxQXZgVJebhCkFZ+oeYGQ7LArM8e0Tu8COaTI6UjvhroI1XXRRj8AyRdIFba/X5Rd6hd wG8k9TwiWW50Ko3GJes1a0to1kPSKcKgUEBnw823rWmws0G3ZeLOWud0WjhF8Gq/0gJM v0HQ== X-Gm-Message-State: APjAAAXO49BWEDSwOSJ7VJo6wcjMYMv50rJ/Tar7WcVSWk3Mf7dgi9iq KkcmVRhBsifi/FnvOjx/skIv8KBa X-Google-Smtp-Source: APXvYqxYINBUTjSgxWoxjO24C/2c+DYPeWoktj+nnO8jieX+c9PFCmjhA6iOoaTacseru5Krqcq0dw== X-Received: by 2002:adf:cd8f:: with SMTP id q15mr10857730wrj.21.1572812820544; Sun, 03 Nov 2019 12:27:00 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 62sm16561752wre.38.2019.11.03.12.27.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Nov 2019 12:27:00 -0800 (PST) Message-Id: In-Reply-To: References: From: "qusielle via GitGitGadget" Date: Sun, 03 Nov 2019 20:26:58 +0000 Subject: [PATCH v2 1/1] add: respect `--ignore-errors` when `lstat()` reports errors MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: Junio C Hamano , qusielle <31454380+qusielle@users.noreply.github.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: qusielle <31454380+qusielle@users.noreply.github.com> "git add --ignore-errors" command fails immediately when lstat returns an error, despite the ignore errors' flag is enabled. There could be files that triggers an error on stat(), when other files proceed correctly. Issue can be reproduced when running git under Cygwin and some target files have utf-8 long names (200+ utf chars). Windows can handle them, but all operations on them failed under Cygwin. Issue can not be reproduced with usual latin/numeric only names. For example, create a file with 220 'й' letters by Windows Explorer, then in Cygwin: # Here and below "ййй..." means the line of й copied 220 times. $ echo -n 'ййй...' | wc -c # check the real size 440 $ ls -la ls: cannot access 'ййй...'$'\320': No such file or directory -????????? ? ? ? ? ? 'ййй...'$'\320' $ ls й* ls: cannot access 'ййй...'$'\320': No such file or directory $ stat й* stat: cannot stat 'ййй...'$'\320': No such file or directory In my perspective, it's okay to skip these problematic files when ignore error flag is specified, but official Git terminates entire git add command when such files come up. But with proposed patch it is the desired behavior: $ git add --ignore-errors . error: ййй... can only add regular files, symbolic links or git-directories # All other files have been added correctly. Signed-off-by: Qusielle --- read-cache.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/read-cache.c b/read-cache.c index 133f790fa4..791ef65bac 100644 --- a/read-cache.c +++ b/read-cache.c @@ -801,8 +801,12 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, int add_file_to_index(struct index_state *istate, const char *path, int flags) { struct stat st; - if (lstat(path, &st)) - die_errno(_("unable to stat '%s'"), path); + if (lstat(path, &st)) { + if (flags & ADD_CACHE_IGNORE_ERRORS) + return -1; + else + die_errno(_("unable to stat '%s'"), path); + } return add_to_index(istate, path, &st, flags); }