From e97285d861355ea1d491119002ec513fd1051b21 Mon Sep 17 00:00:00 2001 From: "shaver%mozilla.org" Date: Mon, 17 Jun 2002 21:03:43 +0000 Subject: [PATCH] Bug 76968: expand ~/ into NS_OS_HOME_DIR in nsLocalFileUnix. r=bzbarsky, sr=blizzard. git-svn-id: svn://10.0.0.236/trunk@123459 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/io/nsLocalFileUnix.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mozilla/xpcom/io/nsLocalFileUnix.cpp b/mozilla/xpcom/io/nsLocalFileUnix.cpp index 281545850ac..5a75bf1c208 100644 --- a/mozilla/xpcom/io/nsLocalFileUnix.cpp +++ b/mozilla/xpcom/io/nsLocalFileUnix.cpp @@ -51,6 +51,7 @@ #include #endif +#include "nsDirectoryServiceDefs.h" #include "nsCRT.h" #include "nsCOMPtr.h" #include "nsMemory.h" @@ -260,7 +261,19 @@ nsLocalFile::Clone(nsIFile **file) NS_IMETHODIMP nsLocalFile::InitWithNativePath(const nsACString &filePath) { - mPath = filePath; + if (Substring(filePath, 0, 2) == NS_LITERAL_CSTRING("~/")) { + nsCOMPtr homeDir; + nsCAutoString homePath; + if (NS_FAILED(NS_GetSpecialDirectory(NS_OS_HOME_DIR, + getter_AddRefs(homeDir))) || + NS_FAILED(homeDir->GetNativePath(homePath))) { + return NS_ERROR_FAILURE; + } + + mPath = homePath + Substring(filePath, 1, filePath.Length() - 1); + } else { + mPath = filePath; + } // trim off trailing slashes ssize_t len = mPath.Length();