Bug 1428543 - Add mozilla::filesystem::Path and use it in nsIFile. r=froydnj

Currently only |value_type| is implemented.

MozReview-Commit-ID: 1mejzvkuako

--HG--
extra : rebase_source : 69e08073adbb9a866db26e515702a0659ece0a70
extra : intermediate-source : 3696381ddfdc19ab2f901ca4247e1cb4efb27731
extra : source : 35d760da1d73dd51614f434c26e5ce80ff690829
This commit is contained in:
Masatoshi Kimura 2017-12-28 03:03:35 +09:00
Родитель aa95c289e7
Коммит 17fb30182d
6 изменённых файлов: 65 добавлений и 16 удалений

32
mfbt/Path.h Normal file
Просмотреть файл

@ -0,0 +1,32 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Represents the native path format on the platform. */
#ifndef mozilla_Path_h
#define mozilla_Path_h
namespace mozilla {
namespace filesystem {
/*
* Mozilla vaiant of std::filesystem::path.
* Only |value_type| is implemented at the moment.
*/
class Path
{
public:
#ifdef XP_WIN
using value_type = char16_t;
#else
using value_type = char;
#endif
};
} /* namespace filesystem */
} /* namespace mozilla */
#endif /* mozilla_Path_h */

Просмотреть файл

@ -63,6 +63,7 @@ EXPORTS.mozilla = [
'Opaque.h',
'OperatorNewExtensions.h',
'Pair.h',
'Path.h',
'PodOperations.h',
'Poison.h',
'Range.h',

Просмотреть файл

@ -120,10 +120,10 @@ FileDescriptorFile::GetPath(nsAString& aRetVal)
return mFile->GetPath(aRetVal);
}
NS_IMETHODIMP
FileDescriptorFile::GetNativePath(nsACString& aRetVal)
PathString
FileDescriptorFile::NativePath()
{
return mFile->GetNativePath(aRetVal);
return mFile->NativePath();
}
NS_IMETHODIMP

Просмотреть файл

@ -9,11 +9,18 @@
struct PRFileDesc;
struct PRLibrary;
#include <stdio.h>
#include "mozilla/Path.h"
#include "nsStringFwd.h"
namespace mozilla {
using PathString = nsTString<filesystem::Path::value_type>;
using PathSubstring = nsTSubstring<filesystem::Path::value_type>;
} // namespace mozilla
%}
[ptr] native PRFileDescStar(PRFileDesc);
[ptr] native PRLibraryStar(PRLibrary);
[ptr] native FILE(FILE);
native PathString(mozilla::PathString);
interface nsISimpleEnumerator;
@ -251,7 +258,10 @@ interface nsIFile : nsISupports
readonly attribute AString target;
[noscript] readonly attribute ACString nativeTarget;
readonly attribute AString path;
[noscript] readonly attribute ACString nativePath;
[notxpcom,nostdcall] PathString nativePath();
%{C++
nsresult GetNativePath(nsACString& aPath);
%}
boolean exists();
boolean isWritable();

Просмотреть файл

@ -591,10 +591,16 @@ nsLocalFile::SetNativeLeafName(const nsACString& aLeafName)
return NS_OK;
}
NS_IMETHODIMP
nsLocalFile::GetNativePath(nsACString& aResult)
nsCString
nsLocalFile::NativePath()
{
aResult = mPath;
return mPath;
}
nsresult
nsIFile::GetNativePath(nsACString& aResult)
{
aResult = NativePath();
return NS_OK;
}

Просмотреть файл

@ -3552,17 +3552,17 @@ nsLocalFile::SetNativeLeafName(const nsACString& aLeafName)
}
NS_IMETHODIMP
nsLocalFile::GetNativePath(nsACString& aResult)
nsString
nsLocalFile::NativePath()
{
return mWorkingPath;
}
nsresult
nsIFile::GetNativePath(nsACString& aResult)
{
//NS_WARNING("This API is lossy. Use GetPath !");
nsAutoString tmp;
nsresult rv = GetPath(tmp);
if (NS_SUCCEEDED(rv)) {
rv = NS_CopyUnicodeToNative(tmp, aResult);
}
return rv;
return NS_CopyUnicodeToNative(NativePath(), aResult);
}