From patchwork Wed Dec 17 21:01:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 4314 Received: (qmail 6058 invoked by alias); 17 Dec 2014 21:02:05 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 6049 invoked by uid 89); 17 Dec 2014 21:02:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.9 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 17 Dec 2014 21:02:03 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBHL1nDK025957 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 17 Dec 2014 16:01:49 -0500 Received: from host2.jankratochvil.net (ovpn-116-142.ams2.redhat.com [10.36.116.142]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBHL1iBp032314 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Wed, 17 Dec 2014 16:01:46 -0500 Date: Wed, 17 Dec 2014 22:01:44 +0100 From: Jan Kratochvil To: Kai Tietz , Steve Ellcey Cc: Eli Zaretskii , brobecker@adacore.com, yao@codesourcery.com, gdb-patches@sourceware.org Subject: [patch] compile: rm -rf -> ftw()+rmdir()+unlink() [Re: [patch] compile: Fix MinGW build] Message-ID: <20141217210144.GA26674@host2.jankratochvil.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1418837391.3123.45.camel@ubuntu-sellcey> <999793426.28919122.1418720642324.JavaMail.zimbra@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes On Tue, 16 Dec 2014 10:04:02 +0100, Kai Tietz wrote: > Why not using here instead an implementation using FTW-API? Done. > At least mingw-w64 added this API recently to runtime for gcc's sake, so > implementation of an 'rm -rf' should be pretty easy. It has built on Fedora 21 x86_64 mingw64 for both 32-bit and 64-bit targets. I am not sure about various other Unices but if the patch gets approved... On Wed, 17 Dec 2014 18:29:51 +0100, Steve Ellcey wrote: > /scratch/sellcey/repos/nightly2/src/binutils-gdb/gdb/compile/compile.c:175:10: error: ignoring return value of 'system', declared with attribute warn_unused_result [-Werror=unused-result] > cc1: all warnings being treated as errors > make[1]: *** [compile.o] Error 1 It should get fixed by this patch. I have briefly tested (on Linux; on MinGW I have only tested the build) it really does delete the directory and its files. OK for check-in? Thanks, Jan gdb/ChangeLog 2014-12-17 Jan Kratochvil * compile/compile.c: Include ftw.h. (do_rmdir_fn): New function. (do_rmdir): Call nftw with it. diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index 414fc35..7dbc819 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -37,6 +37,7 @@ #include "filestuff.h" #include "target.h" #include "osabi.h" +#include @@ -162,17 +163,42 @@ compile_code_command (char *arg, int from_tty) do_cleanups (cleanup); } +/* Helper for do_rmdir. */ + +static int +do_rmdir_fn (const char *fpath, const struct stat *sb, int typeflag, + struct FTW *ftwbuf) +{ + switch (typeflag) + { + case FTW_DP: + if (rmdir (fpath) != 0) + warning (_("Cannot remove 'compile' command directory \"%s\": %s"), + fpath, safe_strerror (errno)); + break; + case FTW_F: + if (unlink (fpath) != 0) + warning (_("Cannot remove 'compile' command file \"%s\": %s"), + fpath, safe_strerror (errno)); + break; + default: + warning (_("Unknown 'typeflag' %d for 'compile' command file \"%s\"."), + typeflag, fpath); + } + + /* Continue the walk. */ + return 0; +} + /* A cleanup function to remove a directory and all its contents. */ static void do_rmdir (void *arg) { const char *dir = arg; - char *zap; - + gdb_assert (strncmp (dir, TMP_PREFIX, strlen (TMP_PREFIX)) == 0); - zap = concat ("rm -rf ", dir, (char *) NULL); - system (zap); + nftw (dir, do_rmdir_fn, 10, FTW_DEPTH | FTW_MOUNT | FTW_PHYS); } /* Return the name of the temporary directory to use for .o files, and