From afa5958a9485d7d3a56946cc562b314f7cf9f345 Mon Sep 17 00:00:00 2001
From: "nweiz@google.com" <nweiz@google.com>
Date: Tue, 11 Dec 2012 21:18:11 +0000
Subject: [PATCH] Fix issue 7215 by relativising a path before checking its
 components.

This includes a couple more miscellaneous fixes.

BUG=7215

Review URL: https://codereview.chromium.org//11528020

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@16002 260f80e4-7a28-3924-810f-c04153c831b5
---
 lib/src/command_lish.dart | 7 ++-----
 lib/src/io.dart           | 2 +-
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/lib/src/command_lish.dart b/lib/src/command_lish.dart
index aa730658..f775b46c 100644
--- a/lib/src/command_lish.dart
+++ b/lib/src/command_lish.dart
@@ -17,8 +17,6 @@ import 'oauth2.dart' as oauth2;
 import 'pub.dart';
 import 'validator.dart';
 
-// TODO(nweiz): Make "publish" the primary name for this command. See issue
-// 6949.
 /// Handles the `lish` and `publish` pub commands.
 class LishCommand extends PubCommand {
   final description = "Publish the current package to pub.dartlang.org.";
@@ -144,9 +142,8 @@ class LishCommand extends PubCommand {
       if (file == null || _BLACKLISTED_FILES.contains(basename(file))) {
         return false;
       }
-      // TODO(nweiz): Since `file` is absolute, this will break if the package
-      // itself is in a directory named "packages" (issue 7215).
-      return !splitPath(file).some(_BLACKLISTED_DIRECTORIES.contains);
+      return !splitPath(relativeTo(file, rootDir))
+          .some(_BLACKLISTED_DIRECTORIES.contains);
     }));
   }
 
diff --git a/lib/src/io.dart b/lib/src/io.dart
index 63879b31..0ecc7b24 100644
--- a/lib/src/io.dart
+++ b/lib/src/io.dart
@@ -74,7 +74,7 @@ List<String> splitPath(path) => _sanitizePath(path).split('/');
 /// performs a path comparison; it doesn't look at the actual filesystem.
 bool isBeneath(entry, dir) {
   var relative = relativeTo(entry, dir);
-  return !path.isAbsolute(relative) && !relative.startsWith('..');
+  return !path.isAbsolute(relative) && splitPath(relative)[0] != '..';
 }
 
 // TODO(nweiz): move this into path.dart.
-- 
GitLab