Skip to content

Commit

Permalink
2005-12-20 Sebastien Pouliot <sebastien@ximian.com>
Browse files Browse the repository at this point in the history
	* Path.cs: Fixed #77007 where a Windows drive is specified with a 
	partial path.


svn path=/trunk/mcs/; revision=54701
  • Loading branch information
Sebastien Pouliot committed Dec 21, 2005
1 parent adee962 commit 4ad0590
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
5 changes: 5 additions & 0 deletions mcs/class/corlib/System.IO/ChangeLog
@@ -1,3 +1,8 @@
2005-12-20 Sebastien Pouliot <sebastien@ximian.com>

* Path.cs: Fixed #77007 where a Windows drive is specified with a
partial path.

2005-12-15 Sebastien Pouliot <sebastien@ximian.com>

* DirectoryInfo.cs: Fixed #76903 where the Name property wasn't
Expand Down
43 changes: 32 additions & 11 deletions mcs/class/corlib/System.IO/Path.cs
Expand Up @@ -212,6 +212,36 @@ public static string GetFullPath (string path)
return fullpath;
}

internal static string WindowsDriveAdjustment (string path)
{
// two special cases to consider when a drive is specified
if (path.Length < 2)
return path;
if ((path [1] != ':') || !Char.IsLetter (path [0]))
return path;

string current = Directory.GetCurrentDirectory ();
// first, only the drive is specified
if (path.Length == 2) {
// then if the current directory is on the same drive
if (current [0] == path [0])
path = current; // we return it
else
path += '\\';
} else if ((path [2] != Path.DirectorySeparatorChar) && (path [2] != Path.AltDirectorySeparatorChar)) {
// second, the drive + a directory is specified *without* a separator between them (e.g. C:dir).
// If the current directory is on the specified drive...
if (current [0] == path [0]) {
// then specified directory is appended to the current drive directory
path = Path.Combine (current, path.Substring (2, path.Length - 2));
} else {
// if not, then just pretend there was a separator (Path.Combine won't work in this case)
path = String.Concat (path.Substring (0, 2), DirectorySeparatorStr, path.Substring (2, path.Length - 2));
}
}
return path;
}

// insecure - do not call directly
internal static string InsecureGetFullPath (string path)
{
Expand All @@ -224,17 +254,8 @@ internal static string InsecureGetFullPath (string path)
}

// adjust for drives, i.e. a special case for windows
if (Environment.IsRunningOnWindows) {
// only a drive is specified
if ((path.Length == 2) && (path [1] == ':') && Char.IsLetter (path [0])) {
// then if the current directory is on the same drive
string current = Directory.GetCurrentDirectory ();
if (current [0] == path [0])
path = current; // we return it
else
path += '\\';
}
}
if (Environment.IsRunningOnWindows)
path = WindowsDriveAdjustment (path);

// if the supplied path ends with a separator...
char end = path [path.Length - 1];
Expand Down

0 comments on commit 4ad0590

Please sign in to comment.