From patchwork Mon Dec 21 17:50:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1419178 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=NYwvolRV; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D06TM3qZKz9sWH for ; Tue, 22 Dec 2020 04:51:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A74B5387084A; Mon, 21 Dec 2020 17:50:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by sourceware.org (Postfix) with ESMTPS id 32A9A385DC1A for ; Mon, 21 Dec 2020 17:50:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 32A9A385DC1A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qt1-x830.google.com with SMTP id j26so7153150qtq.8 for ; Mon, 21 Dec 2020 09:50:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=jnw0pLsf38pBuwwBB271I8XNkNcxAWhZqCAxnejicm4=; b=NYwvolRVyVYzR4XwF3oChBlWMqPCXST9Go2a8R6mM+pwas7N+HMcGuxI6XRb6RY8TI +wXwCGsIfz05qqFwuunz6kgqjk7rdP+uOhpdrOz9Ovlf61YQBZNT71EbiIh+Ol5vEwtv 7twdvVhGD6SSk3HAuLLbOqdfy2BAw+F3nAcZSmGYsXpHQVJGtTYpQ+5Dtlai9I1H4u6V ZTdABNg/eROpDlF2vDrXUCq15pMED4AH3mdhhIAt3JgcAlTsCH/1CKifhoh1scAKDbAT B58puR8jfcudHbxZHE1xbhX6Rzufil7Y3+gN4ootVQ+17FZSwdghBGzmfi/QalYHBUcj Q10w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=jnw0pLsf38pBuwwBB271I8XNkNcxAWhZqCAxnejicm4=; b=Y2OgpMy5vWB0YVnh23I5UniD/tfaGL3ytzFuhl4rwJSwUAZ2IEmMWE27+KheRJtmsY B2r0fdwi6uxdUIq9iaGyIeJZLAYVBtyRkI9x83bVxTvkdJ5doC2VK726Q2NyYAvleiTQ yUnjvRppiNlZL/G3JOZAVt9GBxoU7uuaUSbgiP1uiQOMoFzhe8Pef7pMX+WYvo3dWhLZ vKtW9Xc8CDKRQqbT5YMBieTMlRFgQ699itb6aDPOpNWCoZlg+oIHk0/JdzAscZJcL1+Z Gmvk9YjTUr+kZu45yabpCmil6X3xCodMjM+xBivjIS6R9Noj1uEHsTw3m/Xiik1XZVV3 Q01Q== X-Gm-Message-State: AOAM530RisA/AJqwgKOrOUBE9Zjl669lWlXKPMHDft0e6mQYUy+Q6MMt 0CfHHyk+oDa1abW15Xq07oY= X-Google-Smtp-Source: ABdhPJxXo34341F8DIUQK4aU2dg1xJQNoq4cwaKylxfmg/wG6Y+DKHtEJ6cJs2aGYMjPS5Z7U+LdFw== X-Received: by 2002:ac8:57c4:: with SMTP id w4mr17284630qta.163.1608573055587; Mon, 21 Dec 2020 09:50:55 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:a009:4dd8:8bc:293? ([2620:10d:c091:480::1:35c6]) by smtp.googlemail.com with ESMTPSA id b14sm10562926qtx.36.2020.12.21.09.50.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Dec 2020 09:50:54 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: c++: Windows rename [PR 98412] Message-ID: <7e54b0dc-c364-f050-a363-7015d66c1ac9@acm.org> Date: Mon, 21 Dec 2020 12:50:53 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Some system's rename(2) fails if the target already exists, so delete it first. gcc/cp/ * module.cc (create_dirs): Add logging. (finish_module_processing): Unlink before rename. diff --git i/gcc/cp/module.cc w/gcc/cp/module.cc index fc918d296a2..7e38293545f 100644 --- i/gcc/cp/module.cc +++ w/gcc/cp/module.cc @@ -4693,6 +4693,7 @@ create_dirs (char *path) char sep = *base; *base = 0; int failed = mkdir (path, S_IRWXU | S_IRWXG | S_IRWXO); + dump () && dump ("Mkdir ('%s') errno:=%u", path, failed ? errno : 0); *base = sep; if (failed /* Maybe racing with another creator (of a *different* @@ -19744,8 +19745,17 @@ finish_module_processing (cpp_reader *reader) input_location = loc; } if (to.end ()) - if (rename (tmp_name, path)) - to.set_error (errno); + { + /* Some OS's do not replace NEWNAME if it already + exists. This'll have a race condition in erroneous + concurrent builds. */ + unlink (path); + if (rename (tmp_name, path)) + { + dump () && dump ("Rename ('%s','%s') errno=%u", errno); + to.set_error (errno); + } + } if (to.get_error ()) {