From: Ian Jackson Subject: Re: [PATCH 24/31] libxl: provide libxl__remove_file et al. Date: Wed, 11 Apr 2012 11:56:15 +0100 Message-ID: <20357.25423.953494.600764@mariner.uk.xensource.com> References: <1334084885-14474-1-git-send-email-ian.jackson@eu.citrix.com> <1334084885-14474-25-git-send-email-ian.jackson@eu.citrix.com> <1334138063.5394.97.camel@zakaz.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1334138063.5394.97.camel@zakaz.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org Ian Campbell writes ("Re: [Xen-devel] [PATCH 24/31] libxl: provide libxl__remove_file et al."): > On Tue, 2012-04-10 at 20:07 +0100, Ian Jackson wrote: > > +int libxl__remove_file_or_directory(libxl__gc *gc, const char *path) > > +{ > > + for (;;) { > > + int r = rmdir(path); > > + if (!r) return 0; > > + if (errno == ENOENT) return 0; > > + if (errno == ENOTEMPTY) return libxl__remove_directory(gc, path); > > + if (errno == ENOTDIR) return libxl__remove_file(gc, path); > > + if (errno == EINTR) continue; > > starting to look a bit like a switch statement... Perhaps. I'm not sure I want to obscure the similarity with (and the differences from) the other analogous error-handling code, and those other sites typically have only a couple of errno cases making a switch overkill. Also of course a switch would switch only on errno whereas the branching is on r too, so it would add another level of nesting. > > + for (;;) { > > + int r = rmdir(dirpath); > > + if (!r) break; > > + if (errno == ENOENT) return 0; > > This misses the closedir() at out? Well spotted, fixed. Ian.