From patchwork Fri Apr 13 11:26:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 897910 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HEE0hqmn"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="pXNOQ3bS"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40MwTs57wFz9s27 for ; Fri, 13 Apr 2018 21:26:57 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:Message-Id:Date:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=w4NvFhpAkt5XxxhYqXnzK3xcErez12CPuiiU7zb1d2Q=; b=HEE0hqmn+xwNJG BDYU1d30ORhFQcPse0S8CfUuJ0gokmPN3HcsoolaKbWxeNnmwPRfUZxUNFZpbG6H4/RheK6Rar5BH wdGk3LeG7tPGSIub7oCyK4W/PyCAngmUD6J+ASHBiMtkqFjgRrhwTvgHsZhY3bEiSjaWGERX5Ysmh I8gyvLSGdpr4SFiKhbPO0jzic9EE0E1t47B1ZjbN+mNtUeykQMtWwCM3K0/FQyK4r9gkoBh/F6c15 WqdeNIb4HMiNkkepUmeYF3E28xFHpl5pElwJVomS6Xd+RO1J6cY2raMCd+3jp7MjcBXJ1rcVF717P da2qkBO8n9RVmavWfGUw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6wqy-0004oS-8l; Fri, 13 Apr 2018 11:26:52 +0000 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6wqt-0004mj-Oc for lede-dev@lists.infradead.org; Fri, 13 Apr 2018 11:26:50 +0000 Received: by mail-lf0-x244.google.com with SMTP id u3-v6so12121204lff.5 for ; Fri, 13 Apr 2018 04:26:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+c2BRKYQ3SPqT+PP2VyX+tZyhr0PuyBcGXq6AKYth2M=; b=pXNOQ3bSmdP11DcTs5eFl4X5fuIBFcMkjkasR53lE56RWcpB0Vih/xJSTAWhVeopvG krAj/C9li7OgiQQczaqxE2UtWwh4q16yHVTpz4Hcn6cJuZH7NAO8oku3oqxRTRxFlypm j6TwII2HiFNZiemQvRs+IQyl6pzaKKeG1KGtOKtK6IHkNPzF9QgMn1eBPwto8wtHHJL9 ED9IN7B+IYhpcJIS8FEGTWy2B1KjXAV/3Bs1BOSS+rskCQjr5k3omV3i6h/GX2VG5idG RB0sMW58JRsjPvbSri1QJlyBTgVtOPh03D/RFPpEqbA6UxcmYhKoB/tDvy202KxUtipD oFdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+c2BRKYQ3SPqT+PP2VyX+tZyhr0PuyBcGXq6AKYth2M=; b=dKF3XsbhpFG451Najc6VmWq2cXGmJ5n228QahbEg6Rh18D4i7XqhdsOMz5W3tvvYe7 bYqmDmh4qYqeVta00aDZ4zE0C3Gzi2d0O959Aqv+VUTfEgsaSF3Y894GisMs/NeHzY8l Jg53CZoKu0LST7cjeXvLkfIWpJBYs3F8dNl0GB0qoLisMPfIvN+RHN/yRTWbLsqrA/y7 Fa9C46IDk2dPj8JiVKmJSwLv0QrDUJP3pb1mWoP7KQIdzLRf32+BkCScbPcXEFopgR7h xvCOiODd+ZKcgKaMMEea6PgkYsbZhL235dDA4pSPUtla4lTUPd+WbhuAfqYzFfdV6WPs KH5A== X-Gm-Message-State: ALQs6tBJq0X01NaZES0WWIr6husXVhLzEMlVt3TKme3q7Jku/CWCTh1Z bwxJu6u0Ugt4OmWCmddIDvQ= X-Google-Smtp-Source: AIpwx49n5Dx5UZYzzoakc91sIUrIPv7ONT8JnFLuMtDKESqjEAF9sdlzMHLAbk1GU5rRRIbo4iEaSA== X-Received: by 2002:a19:381c:: with SMTP id f28-v6mr7682821lfa.15.1523618795099; Fri, 13 Apr 2018 04:26:35 -0700 (PDT) Received: from linux-795u.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id l24sm931979ljb.60.2018.04.13.04.26.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Apr 2018 04:26:33 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: John Crispin , lede-dev@lists.infradead.org Date: Fri, 13 Apr 2018 13:26:14 +0200 Message-Id: <20180413112614.21378-1-zajec5@gmail.com> X-Mailer: git-send-email 2.12.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180413_042647_802157_0AC24314 X-CRM114-Status: GOOD ( 14.19 ) X-Spam-Score: 0.1 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:4010:c07:0:0:0:244 listed in] [list.dnswl.org] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (zajec5[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (zajec5[at]gmail.com) -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain Subject: [LEDE-DEV] [PATCH fstools] libfstools: fix foreachdir() to pass dir with a trailing slash X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Rafał Miłecki Commit cc63723d886fd ("overlay: use lstat rather than stat and make sure there are no trailing spaces") changed behavior of foreachdir() breaking some callbacks. Before that modification all callbacks were getting directory with a trailing slash. Above commit started removing them. This broke handle_whiteout() which doesn't work at all since then. It constructs file paths incorrectly: slash is missing between directory and a file name. It seems noone noticed it for years because this issue got hidden by switch2jffs() which also handles whiteouts with its system command "cp -a" call. Fix that regression by setting trailing slash back - right after calling lstat(). Also to keep code simple just skip all entries that aren't directories. This keeps conditions for removing/setting trailing slash trivial. A side effect is not calling callbacks for files which is a free bonus optimization. Fixes: cc63723d886fd ("overlay: use lstat rather than stat and make sure there are no trailing spaces") Signed-off-by: Rafał Miłecki Acked-by: John Crispin --- libfstools/overlay.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libfstools/overlay.c b/libfstools/overlay.c index 1d69f5a..a41364c 100644 --- a/libfstools/overlay.c +++ b/libfstools/overlay.c @@ -88,15 +88,25 @@ foreachdir(const char *dir, int (*cb)(const char*)) sprintf(globdir, "%s/*", dir); + /* Include GLOB_MARK as callbacks expect a trailing slash */ if (!glob(globdir, GLOB_NOESCAPE | GLOB_MARK | GLOB_ONLYDIR, NULL, &gl)) for (j = 0; j < gl.gl_pathc; j++) { char *dir = gl.gl_pathv[j]; int len = strlen(gl.gl_pathv[j]); + int err; - if (len > 1 && dir[len - 1] == '/') + /* Quick way of skipping files */ + if (dir[len - 1] != '/') + continue; + + /* lstat needs path without a trailing slash */ + if (len > 1) dir[len - 1] = '\0'; + err = lstat(gl.gl_pathv[j], &s); + if (len > 1) + dir[len - 1] = '/'; - if (!lstat(gl.gl_pathv[j], &s) && !S_ISLNK(s.st_mode)) + if (!err && !S_ISLNK(s.st_mode)) foreachdir(gl.gl_pathv[j], cb); } cb(dir);