Bug 1175600. Add getRelativePath/setRelativePath to nsIFile. r=froydnj
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 17 Jun 2015 16:17:20 -0400
changeset 267563 a7c5f4c49b1acbd48762091db722e8ffa09a9e5f
parent 267562 a892d303133956d4b7f7c932d88e77a179c27f10
child 267564 e99ec9cc7186c79f0fcaf31db71ffb28cf3ade77
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-esr52@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1175600
milestone41.0a1
Bug 1175600. Add getRelativePath/setRelativePath to nsIFile. r=froydnj
xpcom/io/nsIFile.idl
xpcom/io/nsLocalFileCommon.cpp
--- a/xpcom/io/nsIFile.idl
+++ b/xpcom/io/nsIFile.idl
@@ -37,17 +37,17 @@ interface nsISimpleEnumerator;
  * All methods with string parameters have two forms.  The preferred
  * form operates on UCS-2 encoded characters strings.  An alternate
  * form operates on characters strings encoded in the "native" charset.
  *
  * A string containing characters encoded in the native charset cannot
  * be safely passed to javascript via xpconnect.  Therefore, the "native
  * methods" are not scriptable.
  */
-[scriptable, main_process_scriptable_only, uuid(890b802d-3522-4887-a892-3dab31df30d9), builtinclass]
+[scriptable, main_process_scriptable_only, uuid(2fa6884a-ae65-412a-9d4c-ce6e34544ba1), builtinclass]
 interface nsIFile : nsISupports
 {
     /**
      *  Create Types
      *
      *  NORMAL_FILE_TYPE - A normal file.
      *  DIRECTORY_TYPE   - A directory/folder.
      */
@@ -458,31 +458,58 @@ interface nsIFile : nsISupports
      *  Returns a relative file path in an opaque, XP format. It is therefore
      *  not a native path.
      *
      *  The character set of the string returned from this function is
      *  undefined.  DO NOT TRY TO INTERPRET IT AS HUMAN READABLE TEXT!
      *
      *   @param fromFile
      *       the file from which the descriptor is relative.
-     *       There is no defined result if this param is null.
+     *       Throws if fromFile is null.
      */
     ACString getRelativeDescriptor(in nsIFile fromFile);
 
     /**
      *  setRelativeDescriptor
      *
      *  Initializes the file to the location relative to fromFile using
      *  a string returned by getRelativeDescriptor.
      *
      *   @param fromFile
      *       the file to which the descriptor is relative
      *   @param relative
      *       the relative descriptor obtained from getRelativeDescriptor
      */
     void setRelativeDescriptor(in nsIFile fromFile, in ACString relativeDesc);    
+
+    /**
+     *  getRelativePath
+     *
+     *  Returns a relative file from 'fromFile' to this file as a UTF-8 string.
+     *  Going up the directory tree is represented via "../".  '/' is used as
+     *  the path segment separator.  This is not a native path, since it's UTF-8
+     *  encoded.
+     *
+     *   @param fromFile
+     *       the file from which the path is relative.
+     *       Throws if fromFile is null.
+     */
+    AUTF8String getRelativePath(in nsIFile fromFile);
+
+    /**
+     *  setRelativePath
+     *
+     *  Initializes the file to the location relative to fromFile using
+     *  a string returned by getRelativePath.
+     *
+     *   @param fromFile
+     *       the file from which the path is relative
+     *   @param relative
+     *       the relative path obtained from getRelativePath
+     */
+    void setRelativePath(in nsIFile fromFile, in AUTF8String relativeDesc);
 };
 
 %{C++
 #ifdef MOZILLA_INTERNAL_API
 #include "nsDirectoryServiceUtils.h"
 #endif
 %}
--- a/xpcom/io/nsLocalFileCommon.cpp
+++ b/xpcom/io/nsLocalFileCommon.cpp
@@ -316,8 +316,21 @@ nsLocalFile::SetRelativeDescriptor(nsIFi
     if (nodeEnd != strEnd) { // If there's more left in the string, inc over the '/' nodeEnd is on.
       ++nodeEnd;
     }
     nodeBegin = nodeEnd;
   }
 
   return InitWithFile(targetFile);
 }
+
+NS_IMETHODIMP
+nsLocalFile::GetRelativePath(nsIFile* aFromFile, nsACString& aResult)
+{
+  return GetRelativeDescriptor(aFromFile, aResult);
+}
+
+NS_IMETHODIMP
+nsLocalFile::SetRelativePath(nsIFile* aFromFile,
+                             const nsACString& aRelativePath)
+{
+  return SetRelativeDescriptor(aFromFile, aRelativePath);
+}