2014-05-05 21:30:43 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2014-05-05 21:30:43 +04:00
|
|
|
|
2000-12-09 07:11:05 +03:00
|
|
|
#include "nsLocalFile.h" // includes platform-specific headers
|
2000-04-20 09:44:03 +04:00
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2002-04-09 18:12:24 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2002-04-27 09:33:09 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2008-01-10 00:10:06 +03:00
|
|
|
#include "nsNativeCharsetUtils.h"
|
|
|
|
#include "nsUTF8Utils.h"
|
2017-12-18 10:08:00 +03:00
|
|
|
#include "nsArray.h"
|
2019-03-02 03:01:26 +03:00
|
|
|
#include "nsLocalFileCommon.h"
|
2001-06-22 02:02:47 +04:00
|
|
|
|
2004-05-29 19:37:44 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
|
2019-03-02 03:01:26 +03:00
|
|
|
// Extensions that should be considered 'executable', ie will not allow users
|
|
|
|
// to open immediately without first saving to disk, and potentially provoke
|
|
|
|
// other warnings. PLEASE read the longer comment in
|
2020-06-18 16:09:50 +03:00
|
|
|
// toolkit/components/reputationservice/ApplicationReputation.cpp
|
2019-03-02 03:01:26 +03:00
|
|
|
// before modifying this list!
|
|
|
|
/* static */
|
|
|
|
const char* const sExecutableExts[] = {
|
|
|
|
// clang-format off
|
2020-07-23 15:30:59 +03:00
|
|
|
".accda", // MS Access database
|
|
|
|
".accdb", // MS Access database
|
|
|
|
".accde", // MS Access database
|
|
|
|
".accdr", // MS Access database
|
2019-03-02 03:01:26 +03:00
|
|
|
".ad",
|
|
|
|
".ade", // access project extension
|
|
|
|
".adp",
|
|
|
|
".air", // Adobe AIR installer
|
|
|
|
".app", // executable application
|
|
|
|
".application", // from bug 348763
|
|
|
|
".asp",
|
|
|
|
".bas",
|
|
|
|
".bat",
|
2020-07-23 15:31:06 +03:00
|
|
|
".cer", // Signed certificate file
|
2019-03-02 03:01:26 +03:00
|
|
|
".chm",
|
|
|
|
".cmd",
|
|
|
|
".com",
|
|
|
|
".cpl",
|
|
|
|
".crt",
|
2020-06-18 16:09:50 +03:00
|
|
|
".der",
|
2019-03-02 03:01:26 +03:00
|
|
|
".exe",
|
2020-07-23 15:31:14 +03:00
|
|
|
".fileloc", // Apple finder internet location data file
|
2019-03-02 03:01:26 +03:00
|
|
|
".fxp", // FoxPro compiled app
|
|
|
|
".hlp",
|
|
|
|
".hta",
|
|
|
|
".inf",
|
|
|
|
".ins",
|
|
|
|
".isp",
|
|
|
|
".jar", // java application bundle
|
|
|
|
".jnlp",
|
|
|
|
".js",
|
|
|
|
".jse",
|
|
|
|
".lnk",
|
|
|
|
".mad", // Access Module Shortcut
|
|
|
|
".maf", // Access
|
|
|
|
".mag", // Access Diagram Shortcut
|
|
|
|
".mam", // Access Macro Shortcut
|
|
|
|
".maq", // Access Query Shortcut
|
|
|
|
".mar", // Access Report Shortcut
|
|
|
|
".mas", // Access Stored Procedure
|
|
|
|
".mat", // Access Table Shortcut
|
|
|
|
".mau", // Media Attachment Unit
|
|
|
|
".mav", // Access View Shortcut
|
|
|
|
".maw", // Access Data Access Page
|
|
|
|
".mda", // Access Add-in, MDA Access 2 Workgroup
|
|
|
|
".mdb",
|
|
|
|
".mde",
|
|
|
|
".mdt", // Access Add-in Data
|
|
|
|
".mdw", // Access Workgroup Information
|
|
|
|
".mdz", // Access Wizard Template
|
|
|
|
".msc",
|
|
|
|
".msh", // Microsoft Shell
|
|
|
|
".msh1", // Microsoft Shell
|
|
|
|
".msh1xml", // Microsoft Shell
|
|
|
|
".msh2", // Microsoft Shell
|
|
|
|
".msh2xml", // Microsoft Shell
|
|
|
|
".mshxml", // Microsoft Shell
|
|
|
|
".msi",
|
|
|
|
".msp",
|
|
|
|
".mst",
|
|
|
|
".ops", // Office Profile Settings
|
|
|
|
".pcd",
|
|
|
|
".pif",
|
|
|
|
".plg", // Developer Studio Build Log
|
|
|
|
".prf", // windows system file
|
|
|
|
".prg",
|
|
|
|
".pst",
|
|
|
|
".reg",
|
|
|
|
".scf", // Windows explorer command
|
|
|
|
".scr",
|
|
|
|
".sct",
|
|
|
|
".settingcontent-ms",
|
|
|
|
".shb",
|
|
|
|
".shs",
|
|
|
|
".url",
|
|
|
|
".vb",
|
|
|
|
".vbe",
|
|
|
|
".vbs",
|
|
|
|
".vdx",
|
|
|
|
".vsd",
|
|
|
|
".vsdm",
|
|
|
|
".vsdx",
|
|
|
|
".vsmacros", // Visual Studio .NET Binary-based Macro Project
|
|
|
|
".vss",
|
|
|
|
".vssm",
|
|
|
|
".vssx",
|
|
|
|
".vst",
|
|
|
|
".vstm",
|
|
|
|
".vstx",
|
|
|
|
".vsw",
|
|
|
|
".vsx",
|
|
|
|
".vtx",
|
2020-07-23 15:31:14 +03:00
|
|
|
".webloc", // MacOS website location file
|
2019-03-02 03:01:26 +03:00
|
|
|
".ws",
|
|
|
|
".wsc",
|
|
|
|
".wsf",
|
|
|
|
".wsh"
|
|
|
|
// clang-format on
|
|
|
|
};
|
|
|
|
|
2010-04-27 16:57:34 +04:00
|
|
|
#if !defined(MOZ_WIDGET_COCOA) && !defined(XP_WIN)
|
2002-04-09 18:12:24 +04:00
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsLocalFile::InitWithFile(nsIFile* aFile) {
|
|
|
|
if (NS_WARN_IF(!aFile)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
nsAutoCString path;
|
|
|
|
aFile->GetNativePath(path);
|
2014-05-15 00:15:46 +04:00
|
|
|
if (path.IsEmpty()) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
return InitWithNativePath(path);
|
2002-04-09 18:12:24 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-09-25 16:23:39 +04:00
|
|
|
#define kMaxFilenameLength 255
|
2005-02-19 10:44:59 +03:00
|
|
|
#define kMaxExtensionLength 100
|
2008-01-10 00:10:06 +03:00
|
|
|
#define kMaxSequenceNumberLength 5 // "-9999"
|
|
|
|
// requirement: kMaxExtensionLength <
|
|
|
|
// kMaxFilenameLength - kMaxSequenceNumberLength
|
2000-07-13 03:31:31 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsLocalFile::CreateUnique(uint32_t aType, uint32_t aAttributes) {
|
2014-05-05 21:30:43 +04:00
|
|
|
nsresult rv;
|
|
|
|
bool longName;
|
2008-01-10 00:10:06 +03:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
2014-05-05 21:30:43 +04:00
|
|
|
nsAutoString pathName, leafName, rootName, suffix;
|
|
|
|
rv = GetPath(pathName);
|
2008-01-10 00:10:06 +03:00
|
|
|
#else
|
2014-05-05 21:30:43 +04:00
|
|
|
nsAutoCString pathName, leafName, rootName, suffix;
|
|
|
|
rv = GetNativePath(pathName);
|
2008-01-10 00:10:06 +03:00
|
|
|
#endif
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return rv;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
2018-03-07 01:32:40 +03:00
|
|
|
auto FailedBecauseExists = [&](nsresult aRv) {
|
|
|
|
if (aRv == NS_ERROR_FILE_ACCESS_DENIED) {
|
|
|
|
bool exists;
|
|
|
|
return NS_SUCCEEDED(Exists(&exists)) && exists;
|
|
|
|
}
|
|
|
|
return aRv == NS_ERROR_FILE_ALREADY_EXISTS;
|
|
|
|
};
|
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
longName =
|
|
|
|
(pathName.Length() + kMaxSequenceNumberLength > kMaxFilenameLength);
|
2014-05-15 00:15:46 +04:00
|
|
|
if (!longName) {
|
|
|
|
rv = Create(aType, aAttributes);
|
2018-03-07 01:32:40 +03:00
|
|
|
if (!FailedBecauseExists(rv)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return rv;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
}
|
2008-01-10 00:10:06 +03:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
2014-05-05 21:30:43 +04:00
|
|
|
rv = GetLeafName(leafName);
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return rv;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2000-07-13 03:31:31 +04:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
const int32_t lastDot = leafName.RFindChar(char16_t('.'));
|
2008-01-10 00:10:06 +03:00
|
|
|
#else
|
2014-05-05 21:30:43 +04:00
|
|
|
rv = GetNativeLeafName(leafName);
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return rv;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2000-07-13 03:31:31 +04:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
const int32_t lastDot = leafName.RFindChar('.');
|
2008-01-10 00:10:06 +03:00
|
|
|
#endif
|
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
if (lastDot == kNotFound) {
|
2014-05-05 21:30:43 +04:00
|
|
|
rootName = leafName;
|
2014-05-15 00:15:46 +04:00
|
|
|
} else {
|
2014-05-05 21:30:43 +04:00
|
|
|
suffix = Substring(leafName, lastDot); // include '.'
|
|
|
|
rootName = Substring(leafName, 0, lastDot); // strip suffix and dot
|
|
|
|
}
|
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
if (longName) {
|
2014-05-05 21:30:43 +04:00
|
|
|
int32_t maxRootLength =
|
|
|
|
(kMaxFilenameLength - (pathName.Length() - leafName.Length()) -
|
|
|
|
suffix.Length() - kMaxSequenceNumberLength);
|
|
|
|
|
|
|
|
// We cannot create an item inside a directory whose name is too long.
|
|
|
|
// Also, ensure that at least one character remains after we truncate
|
|
|
|
// the root name, as we don't want to end up with an empty leaf name.
|
2014-05-15 00:15:46 +04:00
|
|
|
if (maxRootLength < 2) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2010-05-02 12:28:26 +04:00
|
|
|
|
2008-01-10 00:10:06 +03:00
|
|
|
#ifdef XP_WIN
|
2014-05-05 21:30:43 +04:00
|
|
|
// ensure that we don't cut the name in mid-UTF16-character
|
|
|
|
rootName.SetLength(NS_IS_LOW_SURROGATE(rootName[maxRootLength])
|
|
|
|
? maxRootLength - 1
|
|
|
|
: maxRootLength);
|
|
|
|
SetLeafName(rootName + suffix);
|
2008-01-10 00:10:06 +03:00
|
|
|
#else
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_IsNativeUTF8()) {
|
2014-05-05 21:30:43 +04:00
|
|
|
// ensure that we don't cut the name in mid-UTF8-character
|
|
|
|
// (assume the name is valid UTF8 to begin with)
|
2014-05-15 00:15:46 +04:00
|
|
|
while (UTF8traits::isInSeq(rootName[maxRootLength])) {
|
2014-05-05 21:30:43 +04:00
|
|
|
--maxRootLength;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
// Another check to avoid ending up with an empty leaf name.
|
2014-05-15 00:15:46 +04:00
|
|
|
if (maxRootLength == 0 && suffix.IsEmpty()) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2008-01-10 00:10:06 +03:00
|
|
|
}
|
2000-07-13 03:31:31 +04:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
rootName.SetLength(maxRootLength);
|
|
|
|
SetNativeLeafName(rootName + suffix);
|
|
|
|
#endif
|
2015-09-08 09:56:16 +03:00
|
|
|
nsresult rvCreate = Create(aType, aAttributes);
|
2018-03-07 01:32:40 +03:00
|
|
|
if (!FailedBecauseExists(rvCreate)) {
|
2015-09-08 09:56:16 +03:00
|
|
|
return rvCreate;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
}
|
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
for (int indx = 1; indx < 10000; ++indx) {
|
2014-05-05 21:30:43 +04:00
|
|
|
// start with "Picture-1.jpg" after "Picture.jpg" exists
|
2008-01-10 00:10:06 +03:00
|
|
|
#ifdef XP_WIN
|
2014-05-05 21:30:43 +04:00
|
|
|
SetLeafName(rootName +
|
|
|
|
NS_ConvertASCIItoUTF16(nsPrintfCString("-%d", indx)) + suffix);
|
2008-01-10 00:10:06 +03:00
|
|
|
#else
|
2014-05-05 21:30:43 +04:00
|
|
|
SetNativeLeafName(rootName + nsPrintfCString("-%d", indx) + suffix);
|
2008-01-10 00:10:06 +03:00
|
|
|
#endif
|
2014-05-15 00:15:46 +04:00
|
|
|
rv = Create(aType, aAttributes);
|
2018-03-07 01:32:40 +03:00
|
|
|
if (NS_SUCCEEDED(rv) || !FailedBecauseExists(rv)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return rv;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// The disk is full, sort of
|
|
|
|
return NS_ERROR_FILE_TOO_BIG;
|
2000-07-13 03:31:31 +04:00
|
|
|
}
|
|
|
|
|
2014-02-11 02:57:01 +04:00
|
|
|
#if defined(XP_WIN)
|
2014-01-04 19:02:17 +04:00
|
|
|
static const char16_t kPathSeparatorChar = '\\';
|
Bug 627277 - Remove (broken) BeOS support. r=biesi,dwitte,gavin,joe,jorendorff,josh,khuey,mfinkle,neil,Pike,roc,shaver,smontagu,taras
2011-02-19 22:10:24 +03:00
|
|
|
#elif defined(XP_UNIX)
|
2014-01-04 19:02:17 +04:00
|
|
|
static const char16_t kPathSeparatorChar = '/';
|
2002-04-09 18:12:24 +04:00
|
|
|
#else
|
|
|
|
# error Need to define file path separator for your platform
|
|
|
|
#endif
|
|
|
|
|
2015-06-17 23:17:22 +03:00
|
|
|
static void SplitPath(char16_t* aPath, nsTArray<char16_t*>& aNodeArray) {
|
2014-05-15 00:15:46 +04:00
|
|
|
if (*aPath == 0) {
|
2015-06-17 23:17:22 +03:00
|
|
|
return;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
if (*aPath == kPathSeparatorChar) {
|
|
|
|
aPath++;
|
|
|
|
}
|
2015-06-17 23:17:22 +03:00
|
|
|
aNodeArray.AppendElement(aPath);
|
2014-05-05 21:30:43 +04:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
for (char16_t* cp = aPath; *cp != 0; ++cp) {
|
2014-05-05 21:30:43 +04:00
|
|
|
if (*cp == kPathSeparatorChar) {
|
|
|
|
*cp++ = 0;
|
2014-05-15 00:15:46 +04:00
|
|
|
if (*cp == 0) {
|
2014-05-05 21:30:43 +04:00
|
|
|
break;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2015-06-17 23:17:22 +03:00
|
|
|
aNodeArray.AppendElement(cp);
|
2002-04-09 18:12:24 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
}
|
2002-04-09 18:12:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsLocalFile::GetRelativeDescriptor(nsIFile* aFromFile, nsACString& aResult) {
|
|
|
|
if (NS_WARN_IF(!aFromFile)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
//
|
2014-05-15 00:15:46 +04:00
|
|
|
// aResult will be UTF-8 encoded
|
2014-05-05 21:30:43 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
nsresult rv;
|
2014-05-15 00:15:46 +04:00
|
|
|
aResult.Truncate(0);
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
nsAutoString thisPath, fromPath;
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<char16_t*, 32> thisNodes;
|
|
|
|
AutoTArray<char16_t*, 32> fromNodes;
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
rv = GetPath(thisPath);
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return rv;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
|
|
|
rv = aFromFile->GetPath(fromPath);
|
|
|
|
if (NS_FAILED(rv)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return rv;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
// get raw pointer to mutable string buffer
|
2018-09-18 23:35:09 +03:00
|
|
|
char16_t* thisPathPtr = thisPath.BeginWriting();
|
|
|
|
char16_t* fromPathPtr = fromPath.BeginWriting();
|
2014-05-05 21:30:43 +04:00
|
|
|
|
2015-06-17 23:17:22 +03:00
|
|
|
SplitPath(thisPathPtr, thisNodes);
|
|
|
|
SplitPath(fromPathPtr, fromNodes);
|
2014-05-05 21:30:43 +04:00
|
|
|
|
2015-06-17 23:17:22 +03:00
|
|
|
size_t nodeIndex;
|
|
|
|
for (nodeIndex = 0;
|
|
|
|
nodeIndex < thisNodes.Length() && nodeIndex < fromNodes.Length();
|
|
|
|
++nodeIndex) {
|
2004-05-29 19:37:44 +04:00
|
|
|
#ifdef XP_WIN
|
2014-08-25 23:17:15 +04:00
|
|
|
if (_wcsicmp(char16ptr_t(thisNodes[nodeIndex]),
|
|
|
|
char16ptr_t(fromNodes[nodeIndex]))) {
|
2014-05-05 21:30:43 +04:00
|
|
|
break;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2004-05-29 19:37:44 +04:00
|
|
|
#else
|
2014-05-15 00:15:46 +04:00
|
|
|
if (nsCRT::strcmp(thisNodes[nodeIndex], fromNodes[nodeIndex])) {
|
2014-05-05 21:30:43 +04:00
|
|
|
break;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2004-05-29 19:37:44 +04:00
|
|
|
#endif
|
2014-05-05 21:30:43 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 23:17:22 +03:00
|
|
|
size_t branchIndex = nodeIndex;
|
|
|
|
for (nodeIndex = branchIndex; nodeIndex < fromNodes.Length(); ++nodeIndex) {
|
2014-05-15 00:15:46 +04:00
|
|
|
aResult.AppendLiteral("../");
|
|
|
|
}
|
2020-12-17 17:58:18 +03:00
|
|
|
StringJoinAppend(aResult, "/"_ns, mozilla::Span{thisNodes}.From(branchIndex),
|
|
|
|
[](nsACString& dest, const auto& thisNode) {
|
|
|
|
// XXX(Bug 1682869) We wouldn't need to reconstruct a
|
|
|
|
// nsDependentString here if SplitPath already returned
|
|
|
|
// nsDependentString. In fact, it seems SplitPath might be
|
|
|
|
// replaced by ParseString?
|
|
|
|
AppendUTF16toUTF8(nsDependentString{thisNode}, dest);
|
|
|
|
});
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2002-04-09 18:12:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsLocalFile::SetRelativeDescriptor(nsIFile* aFromFile,
|
|
|
|
const nsACString& aRelativeDesc) {
|
2014-05-05 21:30:43 +04:00
|
|
|
constexpr auto kParentDirStr = "../"_ns;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
nsCOMPtr<nsIFile> targetFile;
|
2014-05-15 00:15:46 +04:00
|
|
|
nsresult rv = aFromFile->Clone(getter_AddRefs(targetFile));
|
|
|
|
if (NS_FAILED(rv)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return rv;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
//
|
2014-05-15 00:15:46 +04:00
|
|
|
// aRelativeDesc is UTF-8 encoded
|
2014-05-05 21:30:43 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
nsCString::const_iterator strBegin, strEnd;
|
2014-05-15 00:15:46 +04:00
|
|
|
aRelativeDesc.BeginReading(strBegin);
|
|
|
|
aRelativeDesc.EndReading(strEnd);
|
2014-05-05 21:30:43 +04:00
|
|
|
|
|
|
|
nsCString::const_iterator nodeBegin(strBegin), nodeEnd(strEnd);
|
|
|
|
nsCString::const_iterator pos(strBegin);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> parentDir;
|
|
|
|
while (FindInReadable(kParentDirStr, nodeBegin, nodeEnd)) {
|
|
|
|
rv = targetFile->GetParent(getter_AddRefs(parentDir));
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return rv;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
|
|
|
if (!parentDir) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
targetFile = parentDir;
|
|
|
|
|
|
|
|
nodeBegin = nodeEnd;
|
|
|
|
pos = nodeEnd;
|
|
|
|
nodeEnd = strEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeBegin = nodeEnd = pos;
|
|
|
|
while (nodeEnd != strEnd) {
|
|
|
|
FindCharInReadable('/', nodeEnd, strEnd);
|
|
|
|
targetFile->Append(NS_ConvertUTF8toUTF16(Substring(nodeBegin, nodeEnd)));
|
2014-05-15 00:15:46 +04:00
|
|
|
if (nodeEnd != strEnd) { // If there's more left in the string, inc over
|
|
|
|
// the '/' nodeEnd is on.
|
2014-05-05 21:30:43 +04:00
|
|
|
++nodeEnd;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
nodeBegin = nodeEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
return InitWithFile(targetFile);
|
2002-04-09 18:12:24 +04:00
|
|
|
}
|
2015-06-17 23:17:20 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|