public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Go patch committed: Remove "DIR/../" when joining relative import path
@ 2017-06-14 13:37 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2017-06-14 13:37 UTC (permalink / raw)
  To: gcc-patches, gofrontend-dev

[-- Attachment #1: Type: text/plain, Size: 415 bytes --]

This patch to the gofrontend removes an internal DIR/.. when joining
the relative import path to the actual import path.  Otherwise, if DIR
does not exist, the path does not work. This matches what the gc
cmd/compile tool does, because it calls path.Join.

The test for this is the cmd/go tests, to be added in a follow-up CL.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1542 bytes --]

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 249159)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@
-be5fa26b2b1b5d0755bc1c7ce25f3aa26bea9d9c
+c0840d5826abb713487b2d8a04ab249764b21010
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/import.cc
===================================================================
--- gcc/go/gofrontend/import.cc	(revision 249125)
+++ gcc/go/gofrontend/import.cc	(working copy)
@@ -82,6 +82,25 @@ Import::open_package(const std::string&
 	  // A special case.
 	  fn = relative_import_path;
 	}
+      else if (fn[0] == '.' && fn[1] == '.'
+	       && (fn[2] == '\0' || IS_DIR_SEPARATOR(fn[2])))
+	{
+	  // We are going to join relative_import_path and fn, and it
+	  // will look like DIR/../PATH.  But DIR does not necessarily
+	  // exist in this case, and if it doesn't the use of .. will
+	  // fail although it shouldn't.  The gc compiler uses
+	  // path.Join here, which cleans up the .., so we need to do
+	  // the same.
+	  size_t index;
+	  for (index = relative_import_path.length() - 1;
+	       index > 0 && !IS_DIR_SEPARATOR(relative_import_path[index]);
+	       index--)
+	    ;
+	  if (index > 0)
+	    fn = relative_import_path.substr(0, index) + fn.substr(2);
+	  else
+	    fn = relative_import_path + '/' + fn;
+	}
       else
 	fn = relative_import_path + '/' + fn;
       is_local = false;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-06-14 13:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-14 13:37 Go patch committed: Remove "DIR/../" when joining relative import path Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).