Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5E911200C3E for ; Tue, 14 Feb 2017 03:31:08 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 5D2D2160B60; Tue, 14 Feb 2017 02:31:08 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A9E4B160B6C for ; Tue, 14 Feb 2017 03:31:07 +0100 (CET) Received: (qmail 77898 invoked by uid 500); 14 Feb 2017 02:31:06 -0000 Mailing-List: contact commits-help@mynewt.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mynewt.incubator.apache.org Delivered-To: mailing list commits@mynewt.incubator.apache.org Received: (qmail 77887 invoked by uid 99); 14 Feb 2017 02:31:06 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Feb 2017 02:31:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 6E7A21A04C1 for ; Tue, 14 Feb 2017 02:31:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.218 X-Spam-Level: X-Spam-Status: No, score=-6.218 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id BxNRRJA2RJij for ; Tue, 14 Feb 2017 02:31:05 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 484A75FC84 for ; Tue, 14 Feb 2017 02:31:04 +0000 (UTC) Received: (qmail 77813 invoked by uid 99); 14 Feb 2017 02:31:03 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Feb 2017 02:31:03 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 48F2EDFA3D; Tue, 14 Feb 2017 02:31:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sterling@apache.org To: commits@mynewt.incubator.apache.org Date: Tue, 14 Feb 2017 02:31:04 -0000 Message-Id: In-Reply-To: <158fbd9a8ec1437a8523554dd51caf66@git.apache.org> References: <158fbd9a8ec1437a8523554dd51caf66@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] incubator-mynewt-newt git commit: use defer to exit function instead of calling os.Chdir() in exit path archived-at: Tue, 14 Feb 2017 02:31:08 -0000 use defer to exit function instead of calling os.Chdir() in exit path Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/128feabd Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/128feabd Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/128feabd Branch: refs/heads/develop Commit: 128feabdb78930d38312ed9464b5034f861a4ed6 Parents: 432b882 Author: Sterling Hughes Authored: Mon Feb 13 18:27:19 2017 -0800 Committer: Sterling Hughes Committed: Mon Feb 13 18:27:19 2017 -0800 ---------------------------------------------------------------------- newt/cli/pkg_cmds.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/128feabd/newt/cli/pkg_cmds.go ---------------------------------------------------------------------- diff --git a/newt/cli/pkg_cmds.go b/newt/cli/pkg_cmds.go index 75e9a00..4fdecca 100644 --- a/newt/cli/pkg_cmds.go +++ b/newt/cli/pkg_cmds.go @@ -63,6 +63,7 @@ func pkgMoveCmd(cmd *cobra.Command, args []string) { if err != nil { NewtUsage(cmd, util.ChildNewtError(err)) } + defer os.Chdir(wd) if err := os.Chdir(proj.Path() + "/"); err != nil { NewtUsage(cmd, util.ChildNewtError(err)) @@ -73,7 +74,6 @@ func pkgMoveCmd(cmd *cobra.Command, args []string) { */ srcRepoName, srcName, err := newtutil.ParsePackageString(srcLoc) if err != nil { - os.Chdir(wd) NewtUsage(cmd, err) } @@ -84,7 +84,6 @@ func pkgMoveCmd(cmd *cobra.Command, args []string) { srcPkg, err := proj.ResolvePackage(srcRepo, srcName) if err != nil { - os.Chdir(wd) NewtUsage(cmd, err) } @@ -94,7 +93,6 @@ func pkgMoveCmd(cmd *cobra.Command, args []string) { */ repoName, pkgName, err := newtutil.ParsePackageString(dstLoc) if err != nil { - os.Chdir(wd) NewtUsage(cmd, err) } @@ -104,7 +102,6 @@ func pkgMoveCmd(cmd *cobra.Command, args []string) { dstPath += "repos/" + repoName + "/" repo = proj.FindRepo(repoName) if repo == nil { - os.Chdir(wd) NewtUsage(cmd, util.NewNewtError("Destination repo "+ repoName+" does not exist")) } @@ -112,7 +109,6 @@ func pkgMoveCmd(cmd *cobra.Command, args []string) { dstPath += pkgName + "/" if util.NodeExist(dstPath) { - os.Chdir(wd) NewtUsage(cmd, util.NewNewtError("Cannot overwrite existing package, "+ "use pkg delete first")) } @@ -121,14 +117,12 @@ func pkgMoveCmd(cmd *cobra.Command, args []string) { srcLoc, dstLoc) if err := util.MoveDir(srcPkg.BasePath(), dstPath); err != nil { - os.Chdir(wd) NewtUsage(cmd, err) } /* Replace the package name in the pkg.yml file */ pkgData, err := ioutil.ReadFile(dstPath + "/pkg.yml") if err != nil { - os.Chdir(wd) NewtUsage(cmd, err) } @@ -146,8 +140,6 @@ func pkgMoveCmd(cmd *cobra.Command, args []string) { util.MoveDir(dstPath+"/include/"+path.Base(srcPkg.Name()), dstPath+"/include/"+path.Base(pkgName)) } - - os.Chdir(wd) } func pkgRemoveCmd(cmd *cobra.Command, args []string) { @@ -162,6 +154,7 @@ func pkgRemoveCmd(cmd *cobra.Command, args []string) { if err != nil { NewtUsage(cmd, util.ChildNewtError(err)) } + defer os.Chdir(wd) if err := os.Chdir(proj.Path() + "/"); err != nil { NewtUsage(cmd, util.ChildNewtError(err))