2005-04-23 01:41:42 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2004-04-18 14:21:17 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-12-04 01:13:44 +00:00
|
|
|
*
|
2004-04-18 14:21:17 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1999-12-04 01:13:44 +00:00
|
|
|
*
|
2004-04-18 14:21:17 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-12-04 01:13:44 +00:00
|
|
|
*
|
2004-04-18 14:21:17 +00:00
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998-1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-12-04 01:13:44 +00:00
|
|
|
*
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
* Contributor(s):
|
2004-04-18 14:21:17 +00:00
|
|
|
* Mike Shaver <shaver@mozilla.org>
|
|
|
|
* Christopher Blizzard <blizzard@mozilla.org>
|
|
|
|
* Jason Eager <jce2@po.cwru.edu>
|
|
|
|
* Stuart Parmenter <pavlov@netscape.com>
|
|
|
|
* Brendan Eich <brendan@mozilla.org>
|
|
|
|
* Pete Collins <petejc@mozdev.org>
|
|
|
|
* Paul Ashford <arougthopher@lizardland.net>
|
2005-01-30 08:55:16 +00:00
|
|
|
* Fredrik Holmqvist <thesuckiestemail@yahoo.se>
|
2008-09-30 06:06:18 +00:00
|
|
|
* Josh Aas <josh@mozilla.com>
|
2004-04-18 14:21:17 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-12-04 01:13:44 +00:00
|
|
|
|
2001-11-29 00:07:10 +00:00
|
|
|
/**
|
2010-07-22 03:25:24 +00:00
|
|
|
* Implementation of nsIFile for "unixy" systems.
|
1999-12-04 01:13:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <utime.h>
|
2000-01-24 21:28:28 +00:00
|
|
|
#include <dirent.h>
|
2000-02-17 15:35:54 +00:00
|
|
|
#include <ctype.h>
|
2002-05-07 23:07:19 +00:00
|
|
|
#include <locale.h>
|
2000-11-27 11:19:41 +00:00
|
|
|
#if defined(VMS)
|
2001-11-29 00:07:10 +00:00
|
|
|
#include <fabdef.h>
|
2000-11-27 11:19:41 +00:00
|
|
|
#endif
|
1999-12-04 01:13:44 +00:00
|
|
|
|
2010-06-12 02:48:33 +00:00
|
|
|
#if defined(HAVE_SYS_QUOTA_H) && defined(HAVE_LINUX_QUOTA_H)
|
|
|
|
#define USE_LINUX_QUOTACTL
|
2009-09-30 18:26:10 +00:00
|
|
|
#include <sys/quota.h>
|
|
|
|
#endif
|
|
|
|
|
2010-07-30 19:46:20 +00:00
|
|
|
#if (MOZ_PLATFORM_MAEMO == 6)
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QString>
|
2011-02-03 06:31:36 +00:00
|
|
|
#if (MOZ_ENABLE_CONTENTACTION)
|
2010-07-30 19:46:20 +00:00
|
|
|
#include <contentaction/contentaction.h>
|
|
|
|
#endif
|
2011-02-03 06:31:36 +00:00
|
|
|
#endif
|
2010-07-30 19:46:20 +00:00
|
|
|
|
2002-06-17 21:03:43 +00:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
1999-12-04 01:13:44 +00:00
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2000-06-03 09:46:12 +00:00
|
|
|
#include "nsMemory.h"
|
1999-12-04 01:13:44 +00:00
|
|
|
#include "nsIFile.h"
|
2001-06-21 22:02:47 +00:00
|
|
|
#include "nsString.h"
|
2001-08-03 03:26:26 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2003-06-18 23:19:11 +00:00
|
|
|
#include "nsLocalFile.h"
|
2000-01-24 21:28:28 +00:00
|
|
|
#include "nsIComponentManager.h"
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
#include "nsXPIDLString.h"
|
2000-02-17 15:35:54 +00:00
|
|
|
#include "prproces.h"
|
2005-04-23 01:39:51 +00:00
|
|
|
#include "nsIDirectoryEnumerator.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsISimpleEnumerator.h"
|
1999-12-04 01:13:44 +00:00
|
|
|
|
2007-11-26 23:55:34 +00:00
|
|
|
#ifdef MOZ_WIDGET_GTK2
|
2009-08-25 18:58:11 +00:00
|
|
|
#include "nsIGIOService.h"
|
2007-11-26 23:55:34 +00:00
|
|
|
#include "nsIGnomeVFSService.h"
|
|
|
|
#endif
|
|
|
|
|
2010-07-22 03:25:24 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#include "CocoaFileUtils.h"
|
2010-07-26 03:49:28 +00:00
|
|
|
#include "prmem.h"
|
|
|
|
#include "plbase64.h"
|
|
|
|
|
|
|
|
static nsresult MacErrorMapper(OSErr inErr);
|
2010-07-22 03:25:24 +00:00
|
|
|
#endif
|
|
|
|
|
2010-02-09 19:02:11 +00:00
|
|
|
#if (MOZ_PLATFORM_MAEMO == 5)
|
2009-07-16 19:40:28 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include <hildon-uri.h>
|
|
|
|
#include <hildon-mime.h>
|
|
|
|
#include <libosso.h>
|
|
|
|
#endif
|
|
|
|
|
2010-06-14 19:04:16 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
#include "AndroidBridge.h"
|
|
|
|
#include "nsIMIMEService.h"
|
2011-03-04 22:57:25 +00:00
|
|
|
#include <linux/magic.h>
|
2010-06-14 19:04:16 +00:00
|
|
|
#endif
|
|
|
|
|
2002-06-10 18:50:11 +00:00
|
|
|
#include "nsNativeCharsetUtils.h"
|
2006-11-14 22:06:00 +00:00
|
|
|
#include "nsTraceRefcntImpl.h"
|
2002-04-27 05:33:09 +00:00
|
|
|
|
2008-09-30 06:06:18 +00:00
|
|
|
#define ENSURE_STAT_CACHE() \
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
PR_BEGIN_MACRO \
|
2008-09-30 06:06:18 +00:00
|
|
|
if (!FillStatCache()) \
|
|
|
|
return NSRESULT_FOR_ERRNO(); \
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
#define CHECK_mPath() \
|
|
|
|
PR_BEGIN_MACRO \
|
2002-04-27 05:33:09 +00:00
|
|
|
if (mPath.IsEmpty()) \
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
return NS_ERROR_NOT_INITIALIZED; \
|
|
|
|
PR_END_MACRO
|
2000-01-24 21:28:28 +00:00
|
|
|
|
|
|
|
/* directory enumerator */
|
|
|
|
class NS_COM
|
2005-04-23 01:39:51 +00:00
|
|
|
nsDirEnumeratorUnix : public nsISimpleEnumerator,
|
|
|
|
public nsIDirectoryEnumerator
|
2000-01-24 21:28:28 +00:00
|
|
|
{
|
2001-11-29 00:07:10 +00:00
|
|
|
public:
|
2000-01-24 21:28:28 +00:00
|
|
|
nsDirEnumeratorUnix();
|
|
|
|
|
|
|
|
// nsISupports interface
|
|
|
|
NS_DECL_ISUPPORTS
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
// nsISimpleEnumerator interface
|
|
|
|
NS_DECL_NSISIMPLEENUMERATOR
|
|
|
|
|
2005-04-23 01:39:51 +00:00
|
|
|
// nsIDirectoryEnumerator interface
|
|
|
|
NS_DECL_NSIDIRECTORYENUMERATOR
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
NS_IMETHOD Init(nsLocalFile *parent, PRBool ignored);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2004-01-15 06:14:18 +00:00
|
|
|
private:
|
|
|
|
~nsDirEnumeratorUnix();
|
|
|
|
|
2001-11-29 00:07:10 +00:00
|
|
|
protected:
|
2000-01-24 21:28:28 +00:00
|
|
|
NS_IMETHOD GetNextEntry();
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
DIR *mDir;
|
2000-01-24 21:28:28 +00:00
|
|
|
struct dirent *mEntry;
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCString mParentPath;
|
2000-01-24 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nsDirEnumeratorUnix::nsDirEnumeratorUnix() :
|
2001-11-29 00:07:10 +00:00
|
|
|
mDir(nsnull),
|
|
|
|
mEntry(nsnull)
|
2000-01-24 21:28:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDirEnumeratorUnix::~nsDirEnumeratorUnix()
|
|
|
|
{
|
2005-04-23 01:39:51 +00:00
|
|
|
Close();
|
2000-01-24 21:28:28 +00:00
|
|
|
}
|
|
|
|
|
2005-04-23 01:39:51 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(nsDirEnumeratorUnix, nsISimpleEnumerator, nsIDirectoryEnumerator)
|
2000-01-24 21:28:28 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsDirEnumeratorUnix::Init(nsLocalFile *parent, PRBool resolveSymlinks /*ignored*/)
|
2000-01-24 21:28:28 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString dirPath;
|
|
|
|
if (NS_FAILED(parent->GetNativePath(dirPath)) ||
|
|
|
|
dirPath.IsEmpty()) {
|
2000-01-24 21:28:28 +00:00
|
|
|
return NS_ERROR_FILE_INVALID_PATH;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
}
|
2000-01-24 21:28:28 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
if (NS_FAILED(parent->GetNativePath(mParentPath)))
|
2000-01-24 21:28:28 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2001-11-28 15:12:14 +00:00
|
|
|
mDir = opendir(dirPath.get());
|
2000-01-24 21:28:28 +00:00
|
|
|
if (!mDir)
|
|
|
|
return NSRESULT_FOR_ERRNO();
|
|
|
|
return GetNextEntry();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDirEnumeratorUnix::HasMoreElements(PRBool *result)
|
|
|
|
{
|
|
|
|
*result = mDir && mEntry;
|
2005-04-23 01:39:51 +00:00
|
|
|
if (!*result)
|
|
|
|
Close();
|
2000-01-24 21:28:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDirEnumeratorUnix::GetNext(nsISupports **_retval)
|
|
|
|
{
|
2005-04-23 01:39:51 +00:00
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
nsresult rv = GetNextFile(getter_AddRefs(file));
|
|
|
|
if (NS_FAILED(rv))
|
2000-01-24 21:28:28 +00:00
|
|
|
return rv;
|
2005-04-23 01:39:51 +00:00
|
|
|
NS_IF_ADDREF(*_retval = file);
|
|
|
|
return NS_OK;
|
2000-01-24 21:28:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDirEnumeratorUnix::GetNextEntry()
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
errno = 0;
|
|
|
|
mEntry = readdir(mDir);
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
// end of dir or error
|
2000-01-24 21:28:28 +00:00
|
|
|
if (!mEntry)
|
|
|
|
return NSRESULT_FOR_ERRNO();
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
// keep going past "." and ".."
|
2001-11-29 00:07:10 +00:00
|
|
|
} while (mEntry->d_name[0] == '.' &&
|
|
|
|
(mEntry->d_name[1] == '\0' || // .\0
|
|
|
|
(mEntry->d_name[1] == '.' &&
|
|
|
|
mEntry->d_name[2] == '\0'))); // ..\0
|
2000-01-24 21:28:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-23 01:39:51 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDirEnumeratorUnix::GetNextFile(nsIFile **_retval)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
if (!mDir || !mEntry) {
|
|
|
|
*_retval = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-23 02:08:12 +00:00
|
|
|
nsCOMPtr<nsILocalFile> file = new nsLocalFile();
|
2005-04-23 01:39:51 +00:00
|
|
|
if (!file)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = file->InitWithNativePath(mParentPath)) ||
|
2005-04-23 02:08:12 +00:00
|
|
|
NS_FAILED(rv = file->AppendNative(nsDependentCString(mEntry->d_name))))
|
2005-04-23 01:39:51 +00:00
|
|
|
return rv;
|
2005-04-23 02:08:12 +00:00
|
|
|
|
2005-04-23 01:39:51 +00:00
|
|
|
*_retval = file;
|
|
|
|
NS_ADDREF(*_retval);
|
|
|
|
return GetNextEntry();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDirEnumeratorUnix::Close()
|
|
|
|
{
|
|
|
|
if (mDir) {
|
|
|
|
closedir(mDir);
|
|
|
|
mDir = nsnull;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-30 06:06:18 +00:00
|
|
|
nsLocalFile::nsLocalFile()
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-07-18 22:14:16 +00:00
|
|
|
nsLocalFile::nsLocalFile(const nsLocalFile& other)
|
2005-09-13 22:08:52 +00:00
|
|
|
: mPath(other.mPath)
|
2003-07-18 22:14:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-22 03:25:24 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS4(nsLocalFile,
|
|
|
|
nsILocalFileMac,
|
|
|
|
nsILocalFile,
|
2010-07-16 22:35:59 +00:00
|
|
|
nsIFile,
|
2010-07-22 03:25:24 +00:00
|
|
|
nsIHashable)
|
|
|
|
#else
|
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS3(nsLocalFile,
|
2010-07-17 00:31:24 +00:00
|
|
|
nsILocalFile,
|
2010-07-22 03:25:24 +00:00
|
|
|
nsIFile,
|
2008-02-02 02:07:49 +00:00
|
|
|
nsIHashable)
|
2010-07-22 03:25:24 +00:00
|
|
|
#endif
|
1999-12-04 01:13:44 +00:00
|
|
|
|
|
|
|
nsresult
|
2001-11-29 00:07:10 +00:00
|
|
|
nsLocalFile::nsLocalFileConstructor(nsISupports *outer,
|
2002-04-27 05:33:09 +00:00
|
|
|
const nsIID &aIID,
|
|
|
|
void **aInstancePtr)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aInstancePtr);
|
2000-01-24 21:28:28 +00:00
|
|
|
NS_ENSURE_NO_AGGREGATION(outer);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
|
|
|
*aInstancePtr = nsnull;
|
1999-12-04 01:13:44 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> inst = new nsLocalFile();
|
|
|
|
if (!inst)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return inst->QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
|
2008-09-30 06:06:18 +00:00
|
|
|
PRBool
|
2002-01-27 18:02:18 +00:00
|
|
|
nsLocalFile::FillStatCache() {
|
2009-04-16 12:09:21 +00:00
|
|
|
if (STAT(mPath.get(), &mCachedStat) == -1) {
|
2008-08-06 11:09:44 +00:00
|
|
|
// try lstat it may be a symlink
|
2009-04-16 12:09:21 +00:00
|
|
|
if (LSTAT(mPath.get(), &mCachedStat) == -1) {
|
2008-09-30 06:06:18 +00:00
|
|
|
return PR_FALSE;
|
2008-08-06 11:09:44 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-30 06:06:18 +00:00
|
|
|
return PR_TRUE;
|
2002-01-27 18:02:18 +00:00
|
|
|
}
|
|
|
|
|
1999-12-04 01:13:44 +00:00
|
|
|
NS_IMETHODIMP
|
1999-12-22 01:56:45 +00:00
|
|
|
nsLocalFile::Clone(nsIFile **file)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
2003-07-18 22:14:16 +00:00
|
|
|
// Just copy-construct ourselves
|
|
|
|
*file = new nsLocalFile(*this);
|
|
|
|
if (!*file)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-12-04 01:13:44 +00:00
|
|
|
|
1999-12-22 01:56:45 +00:00
|
|
|
NS_ADDREF(*file);
|
2003-07-18 22:14:16 +00:00
|
|
|
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::InitWithNativePath(const nsACString &filePath)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
2004-05-22 22:15:22 +00:00
|
|
|
if (Substring(filePath, 0, 2).EqualsLiteral("~/")) {
|
2002-06-17 21:03:43 +00:00
|
|
|
nsCOMPtr<nsIFile> 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 {
|
2005-02-20 14:28:07 +00:00
|
|
|
if (filePath.IsEmpty() || filePath.First() != '/')
|
2005-02-20 14:05:46 +00:00
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
2002-06-17 21:03:43 +00:00
|
|
|
mPath = filePath;
|
|
|
|
}
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
// trim off trailing slashes
|
|
|
|
ssize_t len = mPath.Length();
|
|
|
|
while ((len > 1) && (mPath[len - 1] == '/'))
|
2001-11-07 04:12:20 +00:00
|
|
|
--len;
|
2002-04-27 05:33:09 +00:00
|
|
|
mPath.SetLength(len);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-01-24 21:28:28 +00:00
|
|
|
nsLocalFile::CreateAllAncestors(PRUint32 permissions)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
// <jband> I promise to play nice
|
2004-02-28 22:34:07 +00:00
|
|
|
char *buffer = mPath.BeginWriting(),
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
*slashp = buffer;
|
2000-01-24 21:28:28 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_NSIFILE
|
2000-10-28 22:17:53 +00:00
|
|
|
fprintf(stderr, "nsIFile: before: %s\n", buffer);
|
2000-01-24 21:28:28 +00:00
|
|
|
#endif
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
while ((slashp = strchr(slashp + 1, '/'))) {
|
2002-04-29 23:35:18 +00:00
|
|
|
/*
|
|
|
|
* Sequences of '/' are equivalent to a single '/'.
|
2000-01-24 21:28:28 +00:00
|
|
|
*/
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
if (slashp[1] == '/')
|
2000-01-24 21:28:28 +00:00
|
|
|
continue;
|
|
|
|
|
2002-04-29 23:35:18 +00:00
|
|
|
/*
|
|
|
|
* If the path has a trailing slash, don't make the last component,
|
|
|
|
* because we'll get EEXIST in Create when we try to build the final
|
|
|
|
* component again, and it's easier to condition the logic here than
|
|
|
|
* there.
|
2000-01-24 21:28:28 +00:00
|
|
|
*/
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
if (slashp[1] == '\0')
|
2000-01-24 21:28:28 +00:00
|
|
|
break;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
/* Temporarily NUL-terminate here */
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
*slashp = '\0';
|
2000-01-24 21:28:28 +00:00
|
|
|
#ifdef DEBUG_NSIFILE
|
2000-10-28 22:17:53 +00:00
|
|
|
fprintf(stderr, "nsIFile: mkdir(\"%s\")\n", buffer);
|
2000-01-24 21:28:28 +00:00
|
|
|
#endif
|
2002-05-01 23:04:46 +00:00
|
|
|
int mkdir_result = mkdir(buffer, permissions);
|
|
|
|
int mkdir_errno = errno;
|
|
|
|
if (mkdir_result == -1) {
|
|
|
|
/*
|
|
|
|
* Always set |errno| to EEXIST if the dir already exists
|
|
|
|
* (we have to do this here since the errno value is not consistent
|
|
|
|
* in all cases - various reasons like different platform,
|
|
|
|
* automounter-controlled dir, etc. can affect it (see bug 125489
|
|
|
|
* for details)).
|
|
|
|
*/
|
|
|
|
if (access(buffer, F_OK) == 0) {
|
|
|
|
mkdir_errno = EEXIST;
|
|
|
|
}
|
|
|
|
}
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
/* Put the / back before we (maybe) return */
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
*slashp = '/';
|
2000-01-24 21:28:28 +00:00
|
|
|
|
2002-04-29 23:35:18 +00:00
|
|
|
/*
|
|
|
|
* We could get EEXIST for an existing file -- not directory --
|
|
|
|
* with the name of one of our ancestors, but that's OK: we'll get
|
|
|
|
* ENOTDIR when we try to make the next component in the path,
|
|
|
|
* either here on back in Create, and error out appropriately.
|
2000-01-24 21:28:28 +00:00
|
|
|
*/
|
2002-05-01 23:04:46 +00:00
|
|
|
if (mkdir_result == -1 && mkdir_errno != EEXIST)
|
|
|
|
return nsresultForErrno(mkdir_errno);
|
2000-01-24 21:28:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_NSIFILE
|
2000-10-28 22:17:53 +00:00
|
|
|
fprintf(stderr, "nsIFile: after: %s\n", buffer);
|
2000-01-24 21:28:28 +00:00
|
|
|
#endif
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
return NS_OK;
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
NS_IMETHODIMP
|
2000-01-24 21:28:28 +00:00
|
|
|
nsLocalFile::OpenNSPRFileDesc(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval)
|
1999-12-22 01:56:45 +00:00
|
|
|
{
|
2001-11-28 15:12:14 +00:00
|
|
|
*_retval = PR_Open(mPath.get(), flags, mode);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
if (! *_retval)
|
2001-12-22 19:08:48 +00:00
|
|
|
return NS_ErrorAccordingToNSPR();
|
1999-12-22 01:56:45 +00:00
|
|
|
|
2009-03-19 20:56:05 +00:00
|
|
|
if (flags & DELETE_ON_CLOSE) {
|
|
|
|
PR_Delete(mPath.get());
|
|
|
|
}
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
return NS_OK;
|
1999-12-22 01:56:45 +00:00
|
|
|
}
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::OpenANSIFileDesc(const char *mode, FILE **_retval)
|
2000-01-24 21:28:28 +00:00
|
|
|
{
|
2001-11-28 15:12:14 +00:00
|
|
|
*_retval = fopen(mPath.get(), mode);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
if (! *_retval)
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-12-22 01:56:45 +00:00
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
return NS_OK;
|
2000-01-24 21:28:28 +00:00
|
|
|
}
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2002-04-29 23:35:18 +00:00
|
|
|
static int
|
|
|
|
do_create(const char *path, PRIntn flags, mode_t mode, PRFileDesc **_retval)
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
{
|
2002-04-29 23:35:18 +00:00
|
|
|
*_retval = PR_Open(path, flags, mode);
|
|
|
|
return *_retval ? 0 : -1;
|
2000-06-27 03:35:32 +00:00
|
|
|
}
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2002-04-29 23:35:18 +00:00
|
|
|
static int
|
|
|
|
do_mkdir(const char *path, PRIntn flags, mode_t mode, PRFileDesc **_retval)
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
{
|
2002-04-29 23:35:18 +00:00
|
|
|
*_retval = nsnull;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
return mkdir(path, mode);
|
2000-06-27 06:10:21 +00:00
|
|
|
}
|
1999-12-22 01:56:45 +00:00
|
|
|
|
2002-04-29 23:35:18 +00:00
|
|
|
nsresult
|
|
|
|
nsLocalFile::CreateAndKeepOpen(PRUint32 type, PRIntn flags,
|
|
|
|
PRUint32 permissions, PRFileDesc **_retval)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
|
|
|
if (type != NORMAL_FILE_TYPE && type != DIRECTORY_TYPE)
|
|
|
|
return NS_ERROR_FILE_UNKNOWN_TYPE;
|
|
|
|
|
|
|
|
int result;
|
2002-04-29 23:35:18 +00:00
|
|
|
int (*createFunc)(const char *, PRIntn, mode_t, PRFileDesc **) =
|
|
|
|
(type == NORMAL_FILE_TYPE) ? do_create : do_mkdir;
|
1999-12-04 01:13:44 +00:00
|
|
|
|
2002-04-29 23:35:18 +00:00
|
|
|
result = createFunc(mPath.get(), flags, permissions, _retval);
|
1999-12-04 01:13:44 +00:00
|
|
|
if (result == -1 && errno == ENOENT) {
|
2002-04-29 23:35:18 +00:00
|
|
|
/*
|
|
|
|
* If we failed because of missing ancestor components, try to create
|
|
|
|
* them and then retry the original creation.
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
*
|
2002-04-29 23:35:18 +00:00
|
|
|
* Ancestor directories get the same permissions as the file we're
|
|
|
|
* creating, with the X bit set for each of (user,group,other) with
|
|
|
|
* an R bit in the original permissions. If you want to do anything
|
|
|
|
* fancy like setgid or sticky bits, do it by hand.
|
1999-12-04 01:13:44 +00:00
|
|
|
*/
|
2000-01-24 21:28:28 +00:00
|
|
|
int dirperm = permissions;
|
|
|
|
if (permissions & S_IRUSR)
|
|
|
|
dirperm |= S_IXUSR;
|
|
|
|
if (permissions & S_IRGRP)
|
|
|
|
dirperm |= S_IXGRP;
|
|
|
|
if (permissions & S_IROTH)
|
|
|
|
dirperm |= S_IXOTH;
|
|
|
|
|
|
|
|
#ifdef DEBUG_NSIFILE
|
2000-10-28 22:17:53 +00:00
|
|
|
fprintf(stderr, "nsIFile: perm = %o, dirperm = %o\n", permissions,
|
2000-01-24 21:28:28 +00:00
|
|
|
dirperm);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (NS_FAILED(CreateAllAncestors(dirperm)))
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-01-24 21:28:28 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_NSIFILE
|
2001-11-28 15:12:14 +00:00
|
|
|
fprintf(stderr, "nsIFile: Create(\"%s\") again\n", mPath.get());
|
2000-01-24 21:28:28 +00:00
|
|
|
#endif
|
2002-04-29 23:35:18 +00:00
|
|
|
result = createFunc(mPath.get(), flags, permissions, _retval);
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
return NSRESULT_FOR_RETURN(result);
|
|
|
|
}
|
|
|
|
|
2002-04-29 23:35:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Create(PRUint32 type, PRUint32 permissions)
|
|
|
|
{
|
|
|
|
PRFileDesc *junk = nsnull;
|
|
|
|
nsresult rv = CreateAndKeepOpen(type,
|
|
|
|
PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE |
|
|
|
|
PR_EXCL,
|
|
|
|
permissions,
|
|
|
|
&junk);
|
|
|
|
if (junk)
|
|
|
|
PR_Close(junk);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-12-04 01:13:44 +00:00
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::AppendNative(const nsACString &fragment)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
if (fragment.IsEmpty())
|
|
|
|
return NS_OK;
|
2000-05-05 05:47:32 +00:00
|
|
|
|
|
|
|
// only one component of path can be appended
|
2002-04-27 05:33:09 +00:00
|
|
|
nsACString::const_iterator begin, end;
|
|
|
|
if (FindCharInReadable('/', fragment.BeginReading(begin),
|
|
|
|
fragment.EndReading(end)))
|
2000-05-05 05:47:32 +00:00
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
return AppendRelativeNativePath(fragment);
|
2000-05-05 05:47:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::AppendRelativeNativePath(const nsACString &fragment)
|
2000-05-05 05:47:32 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
if (fragment.IsEmpty())
|
2001-08-03 03:26:26 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// No leading '/'
|
2002-04-27 05:33:09 +00:00
|
|
|
if (fragment.First() == '/')
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
2000-05-05 05:47:32 +00:00
|
|
|
|
2004-05-22 22:15:22 +00:00
|
|
|
if (mPath.EqualsLiteral("/"))
|
2002-04-27 05:33:09 +00:00
|
|
|
mPath.Append(fragment);
|
|
|
|
else
|
|
|
|
mPath.Append(NS_LITERAL_CSTRING("/") + fragment);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Normalize()
|
|
|
|
{
|
2001-11-29 00:07:10 +00:00
|
|
|
char resolved_path[PATH_MAX] = "";
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
char *resolved_path_ptr = nsnull;
|
|
|
|
|
2001-11-28 15:12:14 +00:00
|
|
|
resolved_path_ptr = realpath(mPath.get(), resolved_path);
|
Bug 627277 - Remove (broken) BeOS support. r=biesi,dwitte,gavin,joe,jorendorff,josh,khuey,mfinkle,neil,Pike,roc,shaver,smontagu,taras
2011-02-19 19:10:24 +00:00
|
|
|
|
2000-02-17 15:35:54 +00:00
|
|
|
// if there is an error, the return is null.
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
if (!resolved_path_ptr)
|
2000-02-17 15:35:54 +00:00
|
|
|
return NSRESULT_FOR_ERRNO();
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
mPath = resolved_path;
|
2000-02-17 15:35:54 +00:00
|
|
|
return NS_OK;
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
void
|
|
|
|
nsLocalFile::LocateNativeLeafName(nsACString::const_iterator &begin,
|
|
|
|
nsACString::const_iterator &end)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
// XXX perhaps we should cache this??
|
|
|
|
|
|
|
|
mPath.BeginReading(begin);
|
|
|
|
mPath.EndReading(end);
|
|
|
|
|
|
|
|
nsACString::const_iterator it = end;
|
|
|
|
nsACString::const_iterator stop = begin;
|
|
|
|
--stop;
|
|
|
|
while (--it != stop) {
|
|
|
|
if (*it == '/') {
|
|
|
|
begin = ++it;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// else, the entire path is the leaf name (which means this
|
|
|
|
// isn't an absolute path... unexpected??)
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::GetNativeLeafName(nsACString &aLeafName)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
nsACString::const_iterator begin, end;
|
|
|
|
LocateNativeLeafName(begin, end);
|
|
|
|
aLeafName = Substring(begin, end);
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::SetNativeLeafName(const nsACString &aLeafName)
|
2000-01-24 21:28:28 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
nsACString::const_iterator begin, end;
|
|
|
|
LocateNativeLeafName(begin, end);
|
|
|
|
mPath.Replace(begin.get() - mPath.get(), Distance(begin, end), aLeafName);
|
2000-01-24 21:28:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::GetNativePath(nsACString &_retval)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
_retval = mPath;
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
nsresult
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::GetNativeTargetPathName(nsIFile *newParent,
|
|
|
|
const nsACString &newName,
|
|
|
|
nsACString &_retval)
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIFile> oldParent;
|
|
|
|
|
|
|
|
if (!newParent) {
|
|
|
|
if (NS_FAILED(rv = GetParent(getter_AddRefs(oldParent))))
|
|
|
|
return rv;
|
|
|
|
newParent = oldParent.get();
|
|
|
|
} else {
|
|
|
|
// check to see if our target directory exists
|
|
|
|
PRBool targetExists;
|
2001-11-28 15:12:14 +00:00
|
|
|
if (NS_FAILED(rv = newParent->Exists(&targetExists)))
|
|
|
|
return rv;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
|
|
|
if (!targetExists) {
|
|
|
|
// XXX create the new directory with some permissions
|
|
|
|
rv = newParent->Create(DIRECTORY_TYPE, 0755);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
} else {
|
|
|
|
// make sure that the target is actually a directory
|
|
|
|
PRBool targetIsDirectory;
|
2001-11-28 15:12:14 +00:00
|
|
|
if (NS_FAILED(rv = newParent->IsDirectory(&targetIsDirectory)))
|
|
|
|
return rv;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
if (!targetIsDirectory)
|
|
|
|
return NS_ERROR_FILE_DESTINATION_NOT_DIR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
nsACString::const_iterator nameBegin, nameEnd;
|
|
|
|
if (!newName.IsEmpty()) {
|
|
|
|
newName.BeginReading(nameBegin);
|
|
|
|
newName.EndReading(nameEnd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
LocateNativeLeafName(nameBegin, nameEnd);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString dirName;
|
|
|
|
if (NS_FAILED(rv = newParent->GetNativePath(dirName)))
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
return rv;
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
_retval = dirName
|
|
|
|
+ NS_LITERAL_CSTRING("/")
|
|
|
|
+ Substring(nameBegin, nameEnd);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-08-03 03:42:04 +00:00
|
|
|
nsresult
|
|
|
|
nsLocalFile::CopyDirectoryTo(nsIFile *newParent)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2002-04-29 23:35:18 +00:00
|
|
|
/*
|
|
|
|
* dirCheck is used for various boolean test results such as from Equals,
|
|
|
|
* Exists, isDir, etc.
|
2002-01-27 14:31:25 +00:00
|
|
|
*/
|
2001-08-03 03:42:04 +00:00
|
|
|
PRBool dirCheck, isSymlink;
|
|
|
|
PRUint32 oldPerms;
|
|
|
|
|
2005-09-15 23:17:17 +00:00
|
|
|
if (NS_FAILED(rv = IsDirectory(&dirCheck)))
|
2001-08-03 03:42:04 +00:00
|
|
|
return rv;
|
|
|
|
if (!dirCheck)
|
2004-05-22 20:02:43 +00:00
|
|
|
return CopyToNative(newParent, EmptyCString());
|
2001-11-29 00:07:10 +00:00
|
|
|
|
2001-08-03 03:42:04 +00:00
|
|
|
if (NS_FAILED(rv = Equals(newParent, &dirCheck)))
|
|
|
|
return rv;
|
|
|
|
if (dirCheck) {
|
|
|
|
// can't copy dir to itself
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = newParent->Exists(&dirCheck)))
|
|
|
|
return rv;
|
2006-09-16 23:53:48 +00:00
|
|
|
// get the dirs old permissions
|
|
|
|
if (NS_FAILED(rv = GetPermissions(&oldPerms)))
|
|
|
|
return rv;
|
2001-08-03 03:42:04 +00:00
|
|
|
if (!dirCheck) {
|
|
|
|
if (NS_FAILED(rv = newParent->Create(DIRECTORY_TYPE, oldPerms)))
|
|
|
|
return rv;
|
2001-11-29 00:07:10 +00:00
|
|
|
} else { // dir exists lets try to use leaf
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString leafName;
|
|
|
|
if (NS_FAILED(rv = GetNativeLeafName(leafName)))
|
2001-08-03 03:42:04 +00:00
|
|
|
return rv;
|
2002-04-27 05:33:09 +00:00
|
|
|
if (NS_FAILED(rv = newParent->AppendNative(leafName)))
|
2001-08-03 03:42:04 +00:00
|
|
|
return rv;
|
|
|
|
if (NS_FAILED(rv = newParent->Exists(&dirCheck)))
|
|
|
|
return rv;
|
|
|
|
if (dirCheck)
|
|
|
|
return NS_ERROR_FILE_ALREADY_EXISTS; // dest exists
|
|
|
|
if (NS_FAILED(rv = newParent->Create(DIRECTORY_TYPE, oldPerms)))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> dirIterator;
|
|
|
|
if (NS_FAILED(rv = GetDirectoryEntries(getter_AddRefs(dirIterator))))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
PRBool hasMore = PR_FALSE;
|
|
|
|
while (dirIterator->HasMoreElements(&hasMore), hasMore) {
|
|
|
|
nsCOMPtr<nsIFile> entry;
|
|
|
|
rv = dirIterator->GetNext((nsISupports**)getter_AddRefs(entry));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
|
|
|
if (NS_FAILED(rv = entry->IsSymlink(&isSymlink)))
|
|
|
|
return rv;
|
2002-01-27 14:31:25 +00:00
|
|
|
if (NS_FAILED(rv = entry->IsDirectory(&dirCheck)))
|
|
|
|
return rv;
|
2001-08-03 03:42:04 +00:00
|
|
|
if (dirCheck && !isSymlink) {
|
|
|
|
nsCOMPtr<nsIFile> destClone;
|
|
|
|
rv = newParent->Clone(getter_AddRefs(destClone));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsILocalFile> newDir(do_QueryInterface(destClone));
|
2004-05-22 20:02:43 +00:00
|
|
|
if (NS_FAILED(rv = entry->CopyToNative(newDir, EmptyCString()))) {
|
2001-08-03 03:42:04 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult rv2;
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString pathName;
|
2002-05-07 23:07:19 +00:00
|
|
|
if (NS_FAILED(rv2 = entry->GetNativePath(pathName)))
|
2001-08-03 03:42:04 +00:00
|
|
|
return rv2;
|
|
|
|
printf("Operation not supported: %s\n", pathName.get());
|
|
|
|
#endif
|
|
|
|
if (rv == NS_ERROR_OUT_OF_MEMORY)
|
|
|
|
return rv;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2004-05-22 20:02:43 +00:00
|
|
|
if (NS_FAILED(rv = entry->CopyToNative(newParent, EmptyCString()))) {
|
2001-08-03 03:42:04 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult rv2;
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString pathName;
|
2002-05-07 23:07:19 +00:00
|
|
|
if (NS_FAILED(rv2 = entry->GetNativePath(pathName)))
|
2001-08-03 03:42:04 +00:00
|
|
|
return rv2;
|
|
|
|
printf("Operation not supported: %s\n", pathName.get());
|
|
|
|
#endif
|
|
|
|
if (rv == NS_ERROR_OUT_OF_MEMORY)
|
|
|
|
return rv;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-04 01:13:44 +00:00
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::CopyToNative(nsIFile *newParent, const nsACString &newName)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
2000-01-24 21:28:28 +00:00
|
|
|
nsresult rv;
|
|
|
|
// check to make sure that this has been initialized properly
|
|
|
|
CHECK_mPath();
|
|
|
|
|
2001-11-28 15:12:14 +00:00
|
|
|
// we copy the parent here so 'newParent' remains immutable
|
|
|
|
nsCOMPtr <nsIFile> workParent;
|
2002-08-29 23:11:20 +00:00
|
|
|
if (newParent) {
|
|
|
|
if (NS_FAILED(rv = newParent->Clone(getter_AddRefs(workParent))))
|
|
|
|
return rv;
|
|
|
|
} else {
|
|
|
|
if (NS_FAILED(rv = GetParent(getter_AddRefs(workParent))))
|
|
|
|
return rv;
|
|
|
|
}
|
2002-04-27 05:33:09 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
// check to see if we are a directory or if we are a file
|
|
|
|
PRBool isDirectory;
|
2001-08-03 03:42:04 +00:00
|
|
|
if (NS_FAILED(rv = IsDirectory(&isDirectory)))
|
|
|
|
return rv;
|
2000-01-24 21:28:28 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString newPathName;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
if (isDirectory) {
|
2002-04-27 05:33:09 +00:00
|
|
|
if (!newName.IsEmpty()) {
|
|
|
|
if (NS_FAILED(rv = workParent->AppendNative(newName)))
|
2001-08-03 03:42:04 +00:00
|
|
|
return rv;
|
|
|
|
} else {
|
2002-04-27 05:33:09 +00:00
|
|
|
if (NS_FAILED(rv = GetNativeLeafName(newPathName)))
|
2001-08-03 03:42:04 +00:00
|
|
|
return rv;
|
2002-04-27 05:33:09 +00:00
|
|
|
if (NS_FAILED(rv = workParent->AppendNative(newPathName)))
|
2001-08-03 03:42:04 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2001-11-28 15:12:14 +00:00
|
|
|
if (NS_FAILED(rv = CopyDirectoryTo(workParent)))
|
2001-08-03 03:42:04 +00:00
|
|
|
return rv;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
} else {
|
2002-04-27 05:33:09 +00:00
|
|
|
rv = GetNativeTargetPathName(workParent, newName, newPathName);
|
2001-11-28 15:12:14 +00:00
|
|
|
if (NS_FAILED(rv))
|
2000-01-24 21:28:28 +00:00
|
|
|
return rv;
|
|
|
|
|
|
|
|
#ifdef DEBUG_blizzard
|
2001-11-28 15:12:14 +00:00
|
|
|
printf("nsLocalFile::CopyTo() %s -> %s\n", mPath.get(), newPathName.get());
|
2000-01-24 21:28:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// actually create the file.
|
2004-04-01 23:13:25 +00:00
|
|
|
nsLocalFile *newFile = new nsLocalFile();
|
2002-04-29 23:35:18 +00:00
|
|
|
if (!newFile)
|
2000-01-24 21:28:28 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2004-04-01 23:13:25 +00:00
|
|
|
nsCOMPtr<nsILocalFile> fileRef(newFile); // release on exit
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
rv = newFile->InitWithNativePath(newPathName);
|
2002-04-29 23:35:18 +00:00
|
|
|
if (NS_FAILED(rv))
|
2000-01-24 21:28:28 +00:00
|
|
|
return rv;
|
|
|
|
|
|
|
|
// get the old permissions
|
|
|
|
PRUint32 myPerms;
|
|
|
|
GetPermissions(&myPerms);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2002-04-29 23:35:18 +00:00
|
|
|
// Create the new file with the old file's permissions, even if write
|
|
|
|
// permission is missing. We can't create with write permission and
|
|
|
|
// then change back to myPerm on all filesystems (FAT on Linux, e.g.).
|
|
|
|
// But we can write to a read-only file on all Unix filesystems if we
|
|
|
|
// open it successfully for writing.
|
2000-01-24 21:28:28 +00:00
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
PRFileDesc *newFD;
|
2002-04-29 23:35:18 +00:00
|
|
|
rv = newFile->CreateAndKeepOpen(NORMAL_FILE_TYPE,
|
|
|
|
PR_WRONLY|PR_CREATE_FILE|PR_TRUNCATE,
|
|
|
|
myPerms,
|
|
|
|
&newFD);
|
|
|
|
if (NS_FAILED(rv))
|
2002-01-27 14:31:25 +00:00
|
|
|
return rv;
|
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
// open the old file, too
|
2002-01-27 14:31:25 +00:00
|
|
|
PRBool specialFile;
|
2002-04-29 23:35:18 +00:00
|
|
|
if (NS_FAILED(rv = IsSpecial(&specialFile))) {
|
|
|
|
PR_Close(newFD);
|
2002-01-27 14:31:25 +00:00
|
|
|
return rv;
|
2002-04-29 23:35:18 +00:00
|
|
|
}
|
2002-01-27 14:31:25 +00:00
|
|
|
if (specialFile) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("Operation not supported: %s\n", mPath.get());
|
|
|
|
#endif
|
|
|
|
// make sure to clean up properly
|
|
|
|
PR_Close(newFD);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-04-29 23:35:18 +00:00
|
|
|
PRFileDesc *oldFD;
|
|
|
|
rv = OpenNSPRFileDesc(PR_RDONLY, myPerms, &oldFD);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// make sure to clean up properly
|
2000-01-24 21:28:28 +00:00
|
|
|
PR_Close(newFD);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
return rv;
|
2000-01-24 21:28:28 +00:00
|
|
|
}
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
#ifdef DEBUG_blizzard
|
2000-01-24 21:28:28 +00:00
|
|
|
PRInt32 totalRead = 0;
|
|
|
|
PRInt32 totalWritten = 0;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
#endif
|
2000-01-24 21:28:28 +00:00
|
|
|
char buf[BUFSIZ];
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
PRInt32 bytesRead;
|
|
|
|
|
|
|
|
while ((bytesRead = PR_Read(oldFD, buf, BUFSIZ)) > 0) {
|
|
|
|
#ifdef DEBUG_blizzard
|
|
|
|
totalRead += bytesRead;
|
|
|
|
#endif
|
2000-01-24 21:28:28 +00:00
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
// PR_Write promises never to do a short write
|
|
|
|
PRInt32 bytesWritten = PR_Write(newFD, buf, bytesRead);
|
|
|
|
if (bytesWritten < 0) {
|
|
|
|
bytesRead = -1;
|
2000-01-24 21:28:28 +00:00
|
|
|
break;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
}
|
|
|
|
NS_ASSERTION(bytesWritten == bytesRead, "short PR_Write?");
|
|
|
|
|
|
|
|
#ifdef DEBUG_blizzard
|
2000-01-24 21:28:28 +00:00
|
|
|
totalWritten += bytesWritten;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
#endif
|
|
|
|
}
|
2000-01-24 21:28:28 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_blizzard
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("read %d bytes, wrote %d bytes\n",
|
2001-11-29 00:07:10 +00:00
|
|
|
totalRead, totalWritten);
|
2000-01-24 21:28:28 +00:00
|
|
|
#endif
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
// close the files
|
|
|
|
PR_Close(newFD);
|
|
|
|
PR_Close(oldFD);
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
// check for read (or write) error after cleaning up
|
2001-08-03 03:42:04 +00:00
|
|
|
if (bytesRead < 0)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-01-24 21:28:28 +00:00
|
|
|
}
|
|
|
|
return rv;
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::CopyToFollowingLinksNative(nsIFile *newParent, const nsACString &newName)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
return CopyToNative(newParent, newName);
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::MoveToNative(nsIFile *newParent, const nsACString &newName)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// check to make sure that this has been initialized properly
|
|
|
|
CHECK_mPath();
|
|
|
|
|
|
|
|
// check to make sure that we have a new parent
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString newPathName;
|
|
|
|
rv = GetNativeTargetPathName(newParent, newName, newPathName);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// try for atomic rename, falling back to copy/delete
|
2001-11-28 15:12:14 +00:00
|
|
|
if (rename(mPath.get(), newPathName.get()) < 0) {
|
2001-05-21 23:15:33 +00:00
|
|
|
#ifdef VMS
|
|
|
|
if (errno == EXDEV || errno == ENXIO) {
|
|
|
|
#else
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
if (errno == EXDEV) {
|
2001-05-21 23:15:33 +00:00
|
|
|
#endif
|
2002-04-27 05:33:09 +00:00
|
|
|
rv = CopyToNative(newParent, newName);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2001-07-24 18:38:25 +00:00
|
|
|
rv = Remove(PR_TRUE);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
} else {
|
|
|
|
rv = NSRESULT_FOR_ERRNO();
|
|
|
|
}
|
|
|
|
}
|
2009-03-24 00:44:37 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Adjust this
|
|
|
|
mPath = newPathName;
|
|
|
|
}
|
2000-08-03 22:17:43 +00:00
|
|
|
return rv;
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-07-24 18:38:25 +00:00
|
|
|
nsLocalFile::Remove(PRBool recursive)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
CHECK_mPath();
|
2008-09-30 06:06:18 +00:00
|
|
|
ENSURE_STAT_CACHE();
|
|
|
|
|
|
|
|
PRBool isSymLink;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2001-11-14 03:42:59 +00:00
|
|
|
nsresult rv = IsSymlink(&isSymLink);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-12-04 01:13:44 +00:00
|
|
|
|
2009-04-07 09:20:05 +00:00
|
|
|
if (isSymLink || !S_ISDIR(mCachedStat.st_mode))
|
2001-11-14 03:42:59 +00:00
|
|
|
return NSRESULT_FOR_RETURN(unlink(mPath.get()));
|
2008-09-30 06:06:18 +00:00
|
|
|
|
2009-04-07 09:20:05 +00:00
|
|
|
if (recursive) {
|
|
|
|
nsDirEnumeratorUnix *dir = new nsDirEnumeratorUnix();
|
|
|
|
if (!dir)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> dirRef(dir); // release on exit
|
2000-01-24 21:28:28 +00:00
|
|
|
|
2009-04-07 09:20:05 +00:00
|
|
|
rv = dir->Init(this, PR_FALSE);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2004-04-02 23:48:18 +00:00
|
|
|
|
2009-04-07 09:20:05 +00:00
|
|
|
PRBool more;
|
|
|
|
while (dir->HasMoreElements(&more), more) {
|
|
|
|
nsCOMPtr<nsISupports> item;
|
|
|
|
rv = dir->GetNext(getter_AddRefs(item));
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
if (NS_FAILED(rv))
|
2009-04-07 09:20:05 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-01-24 21:28:28 +00:00
|
|
|
|
2009-04-07 09:20:05 +00:00
|
|
|
nsCOMPtr<nsIFile> file = do_QueryInterface(item, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-07-29 01:12:34 +00:00
|
|
|
rv = file->Remove(recursive);
|
|
|
|
|
|
|
|
#ifdef ANDROID
|
|
|
|
// See bug 580434 - Bionic gives us just deleted files
|
|
|
|
if (rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)
|
|
|
|
continue;
|
|
|
|
#endif
|
|
|
|
if (NS_FAILED(rv))
|
2009-04-07 09:20:05 +00:00
|
|
|
return rv;
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-07 09:20:05 +00:00
|
|
|
return NSRESULT_FOR_RETURN(rmdir(mPath.get()));
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
NS_IMETHODIMP
|
2001-11-26 08:05:05 +00:00
|
|
|
nsLocalFile::GetLastModifiedTime(PRInt64 *aLastModTime)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
2000-03-15 03:08:28 +00:00
|
|
|
CHECK_mPath();
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
NS_ENSURE_ARG(aLastModTime);
|
|
|
|
|
2000-03-15 03:08:28 +00:00
|
|
|
PRFileInfo64 info;
|
2001-11-28 15:12:14 +00:00
|
|
|
if (PR_GetFileInfo64(mPath.get(), &info) != PR_SUCCESS)
|
2000-03-15 03:08:28 +00:00
|
|
|
return NSRESULT_FOR_ERRNO();
|
2009-04-24 02:22:20 +00:00
|
|
|
PRInt64 modTime = PRInt64(info.modifyTime);
|
|
|
|
if (modTime == 0)
|
|
|
|
*aLastModTime = 0;
|
|
|
|
else
|
|
|
|
*aLastModTime = modTime / PRInt64(PR_USEC_PER_MSEC);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
NS_IMETHODIMP
|
2001-11-26 08:05:05 +00:00
|
|
|
nsLocalFile::SetLastModifiedTime(PRInt64 aLastModTime)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
CHECK_mPath();
|
|
|
|
|
1999-12-04 01:13:44 +00:00
|
|
|
int result;
|
2009-04-24 02:22:20 +00:00
|
|
|
if (aLastModTime != 0) {
|
2008-09-30 06:06:18 +00:00
|
|
|
ENSURE_STAT_CACHE();
|
1999-12-04 01:13:44 +00:00
|
|
|
struct utimbuf ut;
|
|
|
|
ut.actime = mCachedStat.st_atime;
|
2000-03-27 22:04:46 +00:00
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
// convert milliseconds to seconds since the unix epoch
|
2009-04-24 02:22:20 +00:00
|
|
|
ut.modtime = (time_t)(PRFloat64(aLastModTime) / PR_MSEC_PER_SEC);
|
2001-11-28 15:12:14 +00:00
|
|
|
result = utime(mPath.get(), &ut);
|
1999-12-04 01:13:44 +00:00
|
|
|
} else {
|
2001-11-28 15:12:14 +00:00
|
|
|
result = utime(mPath.get(), nsnull);
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
return NSRESULT_FOR_RETURN(result);
|
|
|
|
}
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
NS_IMETHODIMP
|
2001-11-26 08:05:05 +00:00
|
|
|
nsLocalFile::GetLastModifiedTimeOfLink(PRInt64 *aLastModTimeOfLink)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
CHECK_mPath();
|
|
|
|
NS_ENSURE_ARG(aLastModTimeOfLink);
|
|
|
|
|
2009-04-16 12:09:21 +00:00
|
|
|
struct STAT sbuf;
|
|
|
|
if (LSTAT(mPath.get(), &sbuf) == -1)
|
1999-12-04 01:13:44 +00:00
|
|
|
return NSRESULT_FOR_ERRNO();
|
2009-04-24 02:22:20 +00:00
|
|
|
*aLastModTimeOfLink = PRInt64(sbuf.st_mtime) * PRInt64(PR_MSEC_PER_SEC);
|
2000-05-09 19:11:14 +00:00
|
|
|
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-04-29 23:35:18 +00:00
|
|
|
/*
|
|
|
|
* utime(2) may or may not dereference symlinks, joy.
|
1999-12-04 01:13:44 +00:00
|
|
|
*/
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
NS_IMETHODIMP
|
2001-11-26 08:05:05 +00:00
|
|
|
nsLocalFile::SetLastModifiedTimeOfLink(PRInt64 aLastModTimeOfLink)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
2001-11-26 08:05:05 +00:00
|
|
|
return SetLastModifiedTime(aLastModTimeOfLink);
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
2002-04-29 23:35:18 +00:00
|
|
|
/*
|
|
|
|
* Only send back permissions bits: maybe we want to send back the whole
|
|
|
|
* mode_t to permit checks against other file types?
|
1999-12-04 01:13:44 +00:00
|
|
|
*/
|
2001-11-29 00:07:10 +00:00
|
|
|
|
|
|
|
#define NORMALIZE_PERMS(mode) ((mode)& (S_IRWXU | S_IRWXG | S_IRWXO))
|
1999-12-04 01:13:44 +00:00
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
NS_IMETHODIMP
|
1999-12-04 01:13:44 +00:00
|
|
|
nsLocalFile::GetPermissions(PRUint32 *aPermissions)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aPermissions);
|
2008-09-30 06:06:18 +00:00
|
|
|
ENSURE_STAT_CACHE();
|
1999-12-04 01:13:44 +00:00
|
|
|
*aPermissions = NORMALIZE_PERMS(mCachedStat.st_mode);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
NS_IMETHODIMP
|
1999-12-04 01:13:44 +00:00
|
|
|
nsLocalFile::GetPermissionsOfLink(PRUint32 *aPermissionsOfLink)
|
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
CHECK_mPath();
|
1999-12-04 01:13:44 +00:00
|
|
|
NS_ENSURE_ARG(aPermissionsOfLink);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2009-04-16 12:09:21 +00:00
|
|
|
struct STAT sbuf;
|
|
|
|
if (LSTAT(mPath.get(), &sbuf) == -1)
|
1999-12-04 01:13:44 +00:00
|
|
|
return NSRESULT_FOR_ERRNO();
|
|
|
|
*aPermissionsOfLink = NORMALIZE_PERMS(sbuf.st_mode);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
NS_IMETHODIMP
|
1999-12-04 01:13:44 +00:00
|
|
|
nsLocalFile::SetPermissions(PRUint32 aPermissions)
|
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
CHECK_mPath();
|
|
|
|
|
2002-04-29 23:35:18 +00:00
|
|
|
/*
|
|
|
|
* Race condition here: we should use fchmod instead, there's no way to
|
|
|
|
* guarantee the name still refers to the same file.
|
|
|
|
*/
|
2011-03-04 22:57:25 +00:00
|
|
|
if (chmod(mPath.get(), aPermissions) >= 0)
|
|
|
|
return NS_OK;
|
|
|
|
#if defined(ANDROID) && defined(STATFS)
|
|
|
|
// For the time being, this is restricted for use by Android, but we
|
|
|
|
// will figure out what to do for all platforms in bug 638503
|
|
|
|
struct STATFS sfs;
|
|
|
|
if (STATFS(mPath.get(), &sfs) < 0)
|
|
|
|
return NSRESULT_FOR_ERRNO();
|
|
|
|
|
|
|
|
// if this is a FAT file system we can't set file permissions
|
|
|
|
if (sfs.f_type == MSDOS_SUPER_MAGIC )
|
|
|
|
return NS_OK;
|
|
|
|
#endif
|
|
|
|
return NSRESULT_FOR_ERRNO();
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
NS_IMETHODIMP
|
1999-12-04 01:13:44 +00:00
|
|
|
nsLocalFile::SetPermissionsOfLink(PRUint32 aPermissions)
|
|
|
|
{
|
2008-10-08 01:26:41 +00:00
|
|
|
// There isn't a consistent mechanism for doing this on UNIX platforms. We
|
|
|
|
// might want to carefully implement this in the future though.
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-01-24 21:28:28 +00:00
|
|
|
nsLocalFile::GetFileSize(PRInt64 *aFileSize)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aFileSize);
|
2009-04-24 02:22:20 +00:00
|
|
|
*aFileSize = 0;
|
2008-09-30 06:06:18 +00:00
|
|
|
ENSURE_STAT_CACHE();
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2000-11-27 11:19:41 +00:00
|
|
|
#if defined(VMS)
|
|
|
|
/* Only two record formats can report correct file content size */
|
|
|
|
if ((mCachedStat.st_fab_rfm != FAB$C_STMLF) &&
|
|
|
|
(mCachedStat.st_fab_rfm != FAB$C_STMCR)) {
|
2001-06-27 12:29:45 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-11-27 11:19:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-02-07 00:14:33 +00:00
|
|
|
if (!S_ISDIR(mCachedStat.st_mode)) {
|
2009-04-16 12:09:21 +00:00
|
|
|
*aFileSize = (PRInt64)mCachedStat.st_size;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
}
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-01-24 21:28:28 +00:00
|
|
|
nsLocalFile::SetFileSize(PRInt64 aFileSize)
|
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
CHECK_mPath();
|
|
|
|
|
2010-06-01 19:02:42 +00:00
|
|
|
#if defined(ANDROID)
|
|
|
|
/* no truncate on bionic */
|
|
|
|
int fd = open(mPath.get(), O_WRONLY);
|
|
|
|
if (fd == -1)
|
|
|
|
return NSRESULT_FOR_ERRNO();
|
|
|
|
|
|
|
|
int ret = ftruncate(fd, (off_t)aFileSize);
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if (ret == -1)
|
|
|
|
return NSRESULT_FOR_ERRNO();
|
|
|
|
#elif defined(HAVE_TRUNCATE64)
|
2009-04-16 12:09:21 +00:00
|
|
|
if (truncate64(mPath.get(), (off64_t)aFileSize) == -1)
|
2000-01-24 21:28:28 +00:00
|
|
|
return NSRESULT_FOR_ERRNO();
|
2009-04-16 12:09:21 +00:00
|
|
|
#else
|
|
|
|
off_t size = (off_t)aFileSize;
|
|
|
|
if (truncate(mPath.get(), size) == -1)
|
|
|
|
return NSRESULT_FOR_ERRNO();
|
|
|
|
#endif
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
return NS_OK;
|
2000-01-24 21:28:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetFileSizeOfLink(PRInt64 *aFileSize)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
CHECK_mPath();
|
1999-12-04 01:13:44 +00:00
|
|
|
NS_ENSURE_ARG(aFileSize);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2009-04-16 12:09:21 +00:00
|
|
|
struct STAT sbuf;
|
|
|
|
if (LSTAT(mPath.get(), &sbuf) == -1)
|
2008-08-06 11:09:44 +00:00
|
|
|
return NSRESULT_FOR_ERRNO();
|
2009-04-16 12:09:21 +00:00
|
|
|
|
|
|
|
*aFileSize = (PRInt64)sbuf.st_size;
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-12-04 10:07:31 +00:00
|
|
|
#if defined(USE_LINUX_QUOTACTL)
|
2009-09-30 18:26:10 +00:00
|
|
|
/*
|
|
|
|
* Searches /proc/self/mountinfo for given device (Major:Minor),
|
|
|
|
* returns exported name from /dev
|
|
|
|
*
|
|
|
|
* Fails when /proc/self/mountinfo or diven device don't exist.
|
|
|
|
*/
|
|
|
|
static PRBool
|
|
|
|
GetDeviceName(int deviceMajor, int deviceMinor, nsACString &deviceName)
|
|
|
|
{
|
|
|
|
PRBool ret = false;
|
|
|
|
|
|
|
|
const int kMountInfoLineLength = 200;
|
|
|
|
const int kMountInfoDevPosition = 6;
|
|
|
|
|
|
|
|
char mountinfo_line[kMountInfoLineLength];
|
|
|
|
char device_num[kMountInfoLineLength];
|
|
|
|
|
|
|
|
snprintf(device_num,kMountInfoLineLength,"%d:%d", deviceMajor, deviceMinor);
|
|
|
|
|
|
|
|
FILE *f = fopen("/proc/self/mountinfo","rt");
|
|
|
|
if(!f)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
// Expects /proc/self/mountinfo in format:
|
|
|
|
// 'ID ID major:minor root mountpoint flags - type devicename flags'
|
|
|
|
while(fgets(mountinfo_line,kMountInfoLineLength,f)) {
|
|
|
|
char *p_dev = strstr(mountinfo_line,device_num);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < kMountInfoDevPosition && p_dev != NULL; i++) {
|
|
|
|
p_dev = strchr(p_dev,' ');
|
|
|
|
if(p_dev)
|
|
|
|
p_dev++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(p_dev) {
|
|
|
|
char *p_dev_end = strchr(p_dev,' ');
|
|
|
|
if(p_dev_end) {
|
|
|
|
*p_dev_end = '\0';
|
|
|
|
deviceName.Assign(p_dev);
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-12-04 10:07:31 +00:00
|
|
|
#endif
|
2009-09-30 18:26:10 +00:00
|
|
|
|
1999-12-04 01:13:44 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetDiskSpaceAvailable(PRInt64 *aDiskSpaceAvailable)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDiskSpaceAvailable);
|
2000-04-01 20:07:14 +00:00
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
// These systems have the operations necessary to check disk space.
|
2000-04-01 20:07:14 +00:00
|
|
|
|
2009-04-16 12:09:21 +00:00
|
|
|
#ifdef STATFS
|
2000-04-01 20:07:14 +00:00
|
|
|
|
|
|
|
// check to make sure that mPath is properly initialized
|
|
|
|
CHECK_mPath();
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2000-04-01 20:07:14 +00:00
|
|
|
struct STATFS fs_buf;
|
|
|
|
|
2002-04-29 23:35:18 +00:00
|
|
|
/*
|
|
|
|
* Members of the STATFS struct that you should know about:
|
|
|
|
* f_bsize = block size on disk.
|
|
|
|
* f_bavail = number of free blocks available to a non-superuser.
|
|
|
|
* f_bfree = number of total free blocks in file system.
|
2001-11-29 00:07:10 +00:00
|
|
|
*/
|
2000-04-01 20:07:14 +00:00
|
|
|
|
2001-11-28 15:12:14 +00:00
|
|
|
if (STATFS(mPath.get(), &fs_buf) < 0) {
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
// The call to STATFS failed.
|
2000-04-01 20:07:14 +00:00
|
|
|
#ifdef DEBUG
|
2002-04-29 23:35:18 +00:00
|
|
|
printf("ERROR: GetDiskSpaceAvailable: STATFS call FAILED. \n");
|
2000-04-01 20:07:14 +00:00
|
|
|
#endif
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG_DISK_SPACE
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("DiskSpaceAvailable: %d bytes\n",
|
2001-11-29 00:07:10 +00:00
|
|
|
fs_buf.f_bsize * (fs_buf.f_bavail - 1));
|
2000-04-01 20:07:14 +00:00
|
|
|
#endif
|
|
|
|
|
2002-04-29 23:35:18 +00:00
|
|
|
/*
|
|
|
|
* The number of bytes free == The number of free blocks available to
|
|
|
|
* a non-superuser, minus one as a fudge factor, multiplied by the size
|
|
|
|
* of the aforementioned blocks.
|
2001-11-29 00:07:10 +00:00
|
|
|
*/
|
2011-01-19 02:20:35 +00:00
|
|
|
#if defined(SOLARIS) || defined(XP_MACOSX)
|
|
|
|
/* On Solaris and Mac, unit is f_frsize. */
|
2010-06-23 09:32:17 +00:00
|
|
|
*aDiskSpaceAvailable = (PRInt64)fs_buf.f_frsize * (fs_buf.f_bavail - 1);
|
|
|
|
#else
|
2009-04-16 12:09:21 +00:00
|
|
|
*aDiskSpaceAvailable = (PRInt64)fs_buf.f_bsize * (fs_buf.f_bavail - 1);
|
2010-06-23 09:32:17 +00:00
|
|
|
#endif /* SOLARIS */
|
2000-04-01 20:07:14 +00:00
|
|
|
|
2010-06-12 02:48:33 +00:00
|
|
|
#if defined(USE_LINUX_QUOTACTL)
|
2009-09-30 18:26:10 +00:00
|
|
|
|
|
|
|
if(!FillStatCache()) {
|
|
|
|
// Return available size from statfs
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString deviceName;
|
|
|
|
if(!GetDeviceName(major(mCachedStat.st_dev), minor(mCachedStat.st_dev), deviceName)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dqblk dq;
|
|
|
|
if(!quotactl(QCMD(Q_GETQUOTA, USRQUOTA), deviceName.get(), getuid(), (caddr_t)&dq)) {
|
|
|
|
PRInt64 QuotaSpaceAvailable = PRInt64(fs_buf.f_bsize * dq.dqb_bhardlimit);
|
|
|
|
if(QuotaSpaceAvailable < *aDiskSpaceAvailable) {
|
|
|
|
*aDiskSpaceAvailable = QuotaSpaceAvailable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-04-01 20:07:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
#else
|
2002-04-29 23:35:18 +00:00
|
|
|
/*
|
|
|
|
* This platform doesn't have statfs or statvfs. I'm sure that there's
|
|
|
|
* a way to check for free disk space on platforms that don't have statfs
|
|
|
|
* (I'm SURE they have df, for example).
|
2001-11-29 00:07:10 +00:00
|
|
|
*
|
2002-04-29 23:35:18 +00:00
|
|
|
* Until we figure out how to do that, lets be honest and say that this
|
|
|
|
* command isn't implemented properly for these platforms yet.
|
2001-11-29 00:07:10 +00:00
|
|
|
*/
|
2000-04-01 20:07:14 +00:00
|
|
|
#ifdef DEBUG
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("ERROR: GetDiskSpaceAvailable: Not implemented for plaforms without statfs.\n");
|
2000-04-01 20:07:14 +00:00
|
|
|
#endif
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2000-04-01 20:07:14 +00:00
|
|
|
|
2009-04-16 12:09:21 +00:00
|
|
|
#endif /* STATFS */
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetParent(nsIFile **aParent)
|
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
CHECK_mPath();
|
1999-12-04 01:13:44 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
2010-07-22 03:25:24 +00:00
|
|
|
*aParent = nsnull;
|
2000-04-01 20:07:14 +00:00
|
|
|
|
2002-09-07 02:00:31 +00:00
|
|
|
// if '/' we are at the top of the volume, return null
|
|
|
|
if (mPath.Equals("/"))
|
|
|
|
return NS_OK;
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
// <brendan, after jband> I promise to play nice
|
2004-02-28 22:34:07 +00:00
|
|
|
char *buffer = mPath.BeginWriting(),
|
2002-04-27 05:33:09 +00:00
|
|
|
*slashp = buffer;
|
2000-04-01 20:07:14 +00:00
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
// find the last significant slash in buffer
|
|
|
|
slashp = strrchr(buffer, '/');
|
2010-07-22 03:25:24 +00:00
|
|
|
NS_ASSERTION(slashp, "non-canonical path?");
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
if (!slashp)
|
|
|
|
return NS_ERROR_FILE_INVALID_PATH;
|
2000-04-01 20:07:14 +00:00
|
|
|
|
|
|
|
// for the case where we are at '/'
|
2002-04-27 05:33:09 +00:00
|
|
|
if (slashp == buffer)
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
slashp++;
|
2000-04-01 20:07:14 +00:00
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
// temporarily terminate buffer at the last significant slash
|
2002-04-27 05:33:09 +00:00
|
|
|
char c = *slashp;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
*slashp = '\0';
|
2002-04-27 05:33:09 +00:00
|
|
|
|
2000-04-01 20:07:14 +00:00
|
|
|
nsCOMPtr<nsILocalFile> localFile;
|
2002-04-27 05:33:09 +00:00
|
|
|
nsresult rv = NS_NewNativeLocalFile(nsDependentCString(buffer), PR_TRUE,
|
|
|
|
getter_AddRefs(localFile));
|
2001-06-27 12:29:45 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
// make buffer whole again
|
|
|
|
*slashp = c;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && localFile)
|
2002-04-27 05:33:09 +00:00
|
|
|
rv = CallQueryInterface(localFile, aParent);
|
2000-04-01 20:07:14 +00:00
|
|
|
return rv;
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
2002-04-29 23:35:18 +00:00
|
|
|
/*
|
|
|
|
* The results of Exists, isWritable and isReadable are not cached.
|
1999-12-04 01:13:44 +00:00
|
|
|
*/
|
|
|
|
|
2005-01-30 08:55:16 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Exists(PRBool *_retval)
|
|
|
|
{
|
|
|
|
CHECK_mPath();
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
|
|
|
*_retval = (access(mPath.get(), F_OK) == 0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-04 01:13:44 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsWritable(PRBool *_retval)
|
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
CHECK_mPath();
|
1999-12-04 01:13:44 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2001-11-28 15:12:14 +00:00
|
|
|
*_retval = (access(mPath.get(), W_OK) == 0);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
if (*_retval || errno == EACCES)
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
return NSRESULT_FOR_ERRNO();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsReadable(PRBool *_retval)
|
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
CHECK_mPath();
|
1999-12-04 01:13:44 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2001-11-28 15:12:14 +00:00
|
|
|
*_retval = (access(mPath.get(), R_OK) == 0);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
if (*_retval || errno == EACCES)
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
return NSRESULT_FOR_ERRNO();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsExecutable(PRBool *_retval)
|
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
CHECK_mPath();
|
1999-12-04 01:13:44 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2011-06-23 03:07:24 +00:00
|
|
|
// Check extension (bug 663899). On certain platforms, the file
|
|
|
|
// extension may cause the OS to treat it as executable regardless of
|
|
|
|
// the execute bit, such as .jar on Mac OS X. We borrow the code from
|
|
|
|
// nsLocalFileWin, slightly modified.
|
|
|
|
|
|
|
|
// Don't be fooled by symlinks.
|
|
|
|
PRBool symLink;
|
|
|
|
nsresult rv = IsSymlink(&symLink);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsAutoString path;
|
|
|
|
if (symLink)
|
|
|
|
GetTarget(path);
|
|
|
|
else
|
|
|
|
GetPath(path);
|
|
|
|
|
|
|
|
PRInt32 dotIdx = path.RFindChar(PRUnichar('.'));
|
|
|
|
if (dotIdx != kNotFound) {
|
|
|
|
// Convert extension to lower case.
|
|
|
|
PRUnichar *p = path.BeginWriting();
|
|
|
|
for(p += dotIdx + 1; *p; p++)
|
|
|
|
*p += (*p >= L'A' && *p <= L'Z') ? 'a' - 'A' : 0;
|
|
|
|
|
|
|
|
// Search for any of the set of executable extensions.
|
|
|
|
static const char * const executableExts[] = {
|
|
|
|
"air", // Adobe AIR installer
|
|
|
|
"jar"}; // java application bundle
|
|
|
|
nsDependentSubstring ext = Substring(path, dotIdx + 1);
|
|
|
|
for (int i = 0; i < NS_ARRAY_LENGTH(executableExts); i++) {
|
|
|
|
if (ext.EqualsASCII(executableExts[i])) {
|
|
|
|
// Found a match. Set result and quit.
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-23 23:36:58 +00:00
|
|
|
// On OS X, then query Launch Services.
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// Certain Mac applications, such as Classic applications, which
|
|
|
|
// run under Rosetta, might not have the +x mode bit but are still
|
|
|
|
// considered to be executable by Launch Services (bug 646748).
|
|
|
|
CFURLRef url;
|
|
|
|
if (NS_FAILED(GetCFURL(&url))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LSRequestedInfo theInfoRequest = kLSRequestAllInfo;
|
|
|
|
LSItemInfoRecord theInfo;
|
|
|
|
OSStatus result = ::LSCopyItemInfoForURL(url, theInfoRequest, &theInfo);
|
|
|
|
::CFRelease(url);
|
|
|
|
if (result == noErr) {
|
|
|
|
if ((theInfo.flags & kLSItemInfoIsApplication) != 0) {
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Then check the execute bit.
|
2001-11-28 15:12:14 +00:00
|
|
|
*_retval = (access(mPath.get(), X_OK) == 0);
|
2010-03-02 05:51:57 +00:00
|
|
|
#ifdef SOLARIS
|
|
|
|
// On Solaris, access will always return 0 for root user, however
|
|
|
|
// the file is only executable if S_IXUSR | S_IXGRP | S_IXOTH is set.
|
|
|
|
// See bug 351950, https://bugzilla.mozilla.org/show_bug.cgi?id=351950
|
|
|
|
if (*_retval) {
|
|
|
|
struct STAT buf;
|
|
|
|
|
|
|
|
*_retval = (STAT(mPath.get(), &buf) == 0);
|
|
|
|
if (*_retval || errno == EACCES) {
|
|
|
|
*_retval = *_retval &&
|
|
|
|
(buf.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH ));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSRESULT_FOR_ERRNO();
|
|
|
|
}
|
|
|
|
#endif
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
if (*_retval || errno == EACCES)
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
return NSRESULT_FOR_ERRNO();
|
|
|
|
}
|
Bug 627277 - Remove (broken) BeOS support. r=biesi,dwitte,gavin,joe,jorendorff,josh,khuey,mfinkle,neil,Pike,roc,shaver,smontagu,taras
2011-02-19 19:10:24 +00:00
|
|
|
|
1999-12-04 01:13:44 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsDirectory(PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2003-01-13 23:17:49 +00:00
|
|
|
*_retval = PR_FALSE;
|
2008-09-30 06:06:18 +00:00
|
|
|
ENSURE_STAT_CACHE();
|
1999-12-04 01:13:44 +00:00
|
|
|
*_retval = S_ISDIR(mCachedStat.st_mode);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsFile(PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2003-01-13 23:17:49 +00:00
|
|
|
*_retval = PR_FALSE;
|
2008-09-30 06:06:18 +00:00
|
|
|
ENSURE_STAT_CACHE();
|
1999-12-04 01:13:44 +00:00
|
|
|
*_retval = S_ISREG(mCachedStat.st_mode);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsHidden(PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2002-04-27 05:33:09 +00:00
|
|
|
nsACString::const_iterator begin, end;
|
|
|
|
LocateNativeLeafName(begin, end);
|
|
|
|
*_retval = (*begin == '.');
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsSymlink(PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2001-06-28 12:03:47 +00:00
|
|
|
CHECK_mPath();
|
|
|
|
|
2009-04-16 12:09:21 +00:00
|
|
|
struct STAT symStat;
|
|
|
|
if (LSTAT(mPath.get(), &symStat) == -1)
|
2009-04-07 11:38:23 +00:00
|
|
|
return NSRESULT_FOR_ERRNO();
|
2001-06-28 12:03:47 +00:00
|
|
|
*_retval=S_ISLNK(symStat.st_mode);
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsSpecial(PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2008-09-30 06:06:18 +00:00
|
|
|
ENSURE_STAT_CACHE();
|
2002-01-27 14:31:25 +00:00
|
|
|
*_retval = S_ISCHR(mCachedStat.st_mode) ||
|
2001-11-29 00:07:10 +00:00
|
|
|
S_ISBLK(mCachedStat.st_mode) ||
|
2002-01-28 07:02:02 +00:00
|
|
|
#ifdef S_ISSOCK
|
2002-01-27 14:31:25 +00:00
|
|
|
S_ISSOCK(mCachedStat.st_mode) ||
|
2002-01-28 07:02:02 +00:00
|
|
|
#endif
|
2001-11-29 00:07:10 +00:00
|
|
|
S_ISFIFO(mCachedStat.st_mode);
|
2001-06-30 13:30:32 +00:00
|
|
|
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(inFile);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2000-01-24 21:28:28 +00:00
|
|
|
*_retval = PR_FALSE;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString inPath;
|
2009-07-08 15:26:07 +00:00
|
|
|
nsresult rv = inFile->GetNativePath(inPath);
|
|
|
|
if (NS_FAILED(rv))
|
2000-01-24 21:28:28 +00:00
|
|
|
return rv;
|
|
|
|
|
2009-07-08 15:26:07 +00:00
|
|
|
// We don't need to worry about "/foo/" vs. "/foo" here
|
|
|
|
// because trailing slashes are stripped on init.
|
|
|
|
*_retval = !strcmp(inPath.get(), mPath.get());
|
2000-01-24 21:28:28 +00:00
|
|
|
return NS_OK;
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-01-28 23:53:59 +00:00
|
|
|
nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
CHECK_mPath();
|
1999-12-04 01:13:44 +00:00
|
|
|
NS_ENSURE_ARG(inFile);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString inPath;
|
2000-01-24 21:28:28 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
if (NS_FAILED(rv = inFile->GetNativePath(inPath)))
|
2000-01-24 21:28:28 +00:00
|
|
|
return rv;
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
*_retval = PR_FALSE;
|
2000-01-24 21:28:28 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
ssize_t len = mPath.Length();
|
2009-07-08 15:26:07 +00:00
|
|
|
if (strncmp(mPath.get(), inPath.get(), len) == 0) {
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
// Now make sure that the |inFile|'s path has a separator at len,
|
|
|
|
// which implies that it has more components after len.
|
2002-04-27 05:33:09 +00:00
|
|
|
if (inPath[len] == '/')
|
2000-01-28 23:53:59 +00:00
|
|
|
*_retval = PR_TRUE;
|
2000-01-24 21:28:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::GetNativeTarget(nsACString &_retval)
|
1999-12-04 01:13:44 +00:00
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
CHECK_mPath();
|
2002-04-27 05:33:09 +00:00
|
|
|
_retval.Truncate();
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2009-04-16 12:09:21 +00:00
|
|
|
struct STAT symStat;
|
|
|
|
if (LSTAT(mPath.get(), &symStat) == -1)
|
2009-04-07 11:38:41 +00:00
|
|
|
return NSRESULT_FOR_ERRNO();
|
|
|
|
|
2001-06-29 17:43:59 +00:00
|
|
|
if (!S_ISLNK(symStat.st_mode))
|
1999-12-04 01:13:44 +00:00
|
|
|
return NS_ERROR_FILE_INVALID_PATH;
|
|
|
|
|
2009-04-07 11:38:41 +00:00
|
|
|
PRInt32 size = (PRInt32)symStat.st_size;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
char *target = (char *)nsMemory::Alloc(size + 1);
|
1999-12-04 01:13:44 +00:00
|
|
|
if (!target)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2001-11-06 01:42:00 +00:00
|
|
|
if (readlink(mPath.get(), target, (size_t)size) < 0) {
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
nsMemory::Free(target);
|
|
|
|
return NSRESULT_FOR_ERRNO();
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
target[size] = '\0';
|
2001-11-06 01:42:00 +00:00
|
|
|
|
2009-04-07 11:38:41 +00:00
|
|
|
nsresult rv = NS_OK;
|
2003-06-21 00:15:41 +00:00
|
|
|
nsCOMPtr<nsIFile> self(this);
|
2009-04-07 11:38:41 +00:00
|
|
|
PRInt32 maxLinks = 40;
|
|
|
|
while (PR_TRUE) {
|
|
|
|
if (maxLinks-- == 0) {
|
|
|
|
rv = NS_ERROR_FILE_UNRESOLVABLE_SYMLINK;
|
|
|
|
break;
|
|
|
|
}
|
2001-11-06 01:42:00 +00:00
|
|
|
|
|
|
|
if (target[0] != '/') {
|
2009-04-07 11:38:41 +00:00
|
|
|
nsCOMPtr<nsIFile> parent;
|
|
|
|
if (NS_FAILED(rv = self->GetParent(getter_AddRefs(parent))))
|
|
|
|
break;
|
2001-11-06 01:42:00 +00:00
|
|
|
nsCOMPtr<nsILocalFile> localFile(do_QueryInterface(parent, &rv));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
2002-04-27 05:33:09 +00:00
|
|
|
if (NS_FAILED(rv = localFile->AppendRelativeNativePath(nsDependentCString(target))))
|
2001-11-06 01:42:00 +00:00
|
|
|
break;
|
2002-04-27 05:33:09 +00:00
|
|
|
if (NS_FAILED(rv = localFile->GetNativePath(_retval)))
|
2001-11-06 01:42:00 +00:00
|
|
|
break;
|
|
|
|
self = parent;
|
|
|
|
} else {
|
2009-04-07 11:38:41 +00:00
|
|
|
_retval = target;
|
2001-11-06 01:42:00 +00:00
|
|
|
}
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
const nsPromiseFlatCString &flatRetval = PromiseFlatCString(_retval);
|
|
|
|
|
2009-04-07 11:38:41 +00:00
|
|
|
// Any failure in testing the current target we'll just interpret
|
|
|
|
// as having reached our destiny.
|
2009-04-16 12:09:21 +00:00
|
|
|
if (LSTAT(flatRetval.get(), &symStat) == -1)
|
2001-11-06 01:42:00 +00:00
|
|
|
break;
|
2009-04-07 11:38:41 +00:00
|
|
|
|
|
|
|
// And of course we're done if it isn't a symlink.
|
|
|
|
if (!S_ISLNK(symStat.st_mode))
|
2001-11-06 01:42:00 +00:00
|
|
|
break;
|
2009-04-07 11:38:41 +00:00
|
|
|
|
|
|
|
PRInt32 newSize = (PRInt32)symStat.st_size;
|
|
|
|
if (newSize > size) {
|
|
|
|
char *newTarget = (char *)nsMemory::Realloc(target, newSize + 1);
|
|
|
|
if (!newTarget) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
target = newTarget;
|
|
|
|
size = newSize;
|
2001-11-06 01:42:00 +00:00
|
|
|
}
|
2009-04-07 11:38:41 +00:00
|
|
|
|
|
|
|
PRInt32 linkLen = readlink(flatRetval.get(), target, size);
|
|
|
|
if (linkLen == -1) {
|
2001-11-06 01:42:00 +00:00
|
|
|
rv = NSRESULT_FOR_ERRNO();
|
|
|
|
break;
|
|
|
|
}
|
2009-04-07 11:38:41 +00:00
|
|
|
target[linkLen] = '\0';
|
2001-11-06 01:42:00 +00:00
|
|
|
}
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
nsMemory::Free(target);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
_retval.Truncate();
|
2001-11-06 01:42:00 +00:00
|
|
|
return rv;
|
1999-12-04 01:13:44 +00:00
|
|
|
}
|
2000-01-24 21:28:28 +00:00
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
NS_IMETHODIMP
|
2000-07-12 23:31:31 +00:00
|
|
|
nsLocalFile::GetFollowLinks(PRBool *aFollowLinks)
|
|
|
|
{
|
|
|
|
*aFollowLinks = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-11-29 00:07:10 +00:00
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
NS_IMETHODIMP
|
2000-07-12 23:31:31 +00:00
|
|
|
nsLocalFile::SetFollowLinks(PRBool aFollowLinks)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator **entries)
|
|
|
|
{
|
2004-04-02 23:48:18 +00:00
|
|
|
nsDirEnumeratorUnix *dir = new nsDirEnumeratorUnix();
|
2000-01-24 21:28:28 +00:00
|
|
|
if (!dir)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2004-04-02 23:48:18 +00:00
|
|
|
NS_ADDREF(dir);
|
2000-01-24 21:28:28 +00:00
|
|
|
nsresult rv = dir->Init(this, PR_FALSE);
|
2004-04-02 23:48:18 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
*entries = nsnull;
|
|
|
|
NS_RELEASE(dir);
|
|
|
|
} else {
|
|
|
|
*entries = dir; // transfer reference
|
|
|
|
}
|
2000-01-24 21:28:28 +00:00
|
|
|
|
2004-04-02 23:48:18 +00:00
|
|
|
return rv;
|
2000-01-24 21:28:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Load(PRLibrary **_retval)
|
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
CHECK_mPath();
|
2000-01-24 21:28:28 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
|
2006-11-14 22:06:00 +00:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsTraceRefcntImpl::SetActivityIsLegal(PR_FALSE);
|
|
|
|
#endif
|
|
|
|
|
2006-04-13 17:24:12 +00:00
|
|
|
*_retval = PR_LoadLibrary(mPath.get());
|
2001-11-17 20:23:48 +00:00
|
|
|
|
2006-11-14 22:06:00 +00:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsTraceRefcntImpl::SetActivityIsLegal(PR_TRUE);
|
|
|
|
#endif
|
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
if (!*_retval)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-07-17 15:03:05 +00:00
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::GetPersistentDescriptor(nsACString &aPersistentDescriptor)
|
2000-07-17 15:03:05 +00:00
|
|
|
{
|
2002-04-27 05:33:09 +00:00
|
|
|
return GetNativePath(aPersistentDescriptor);
|
2000-07-17 15:03:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-04-27 05:33:09 +00:00
|
|
|
nsLocalFile::SetPersistentDescriptor(const nsACString &aPersistentDescriptor)
|
2000-07-17 15:03:05 +00:00
|
|
|
{
|
2010-07-26 03:49:28 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (aPersistentDescriptor.IsEmpty())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// Support pathnames as user-supplied descriptors if they begin with '/'
|
|
|
|
// or '~'. These characters do not collide with the base64 set used for
|
|
|
|
// encoding alias records.
|
|
|
|
char first = aPersistentDescriptor.First();
|
|
|
|
if (first == '/' || first == '~')
|
|
|
|
return InitWithNativePath(aPersistentDescriptor);
|
|
|
|
|
|
|
|
PRUint32 dataSize = aPersistentDescriptor.Length();
|
|
|
|
char* decodedData = PL_Base64Decode(PromiseFlatCString(aPersistentDescriptor).get(), dataSize, nsnull);
|
|
|
|
if (!decodedData) {
|
|
|
|
NS_ERROR("SetPersistentDescriptor was given bad data");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cast to an alias record and resolve.
|
|
|
|
AliasRecord aliasHeader = *(AliasPtr)decodedData;
|
|
|
|
PRInt32 aliasSize = ::GetAliasSizeFromPtr(&aliasHeader);
|
|
|
|
if (aliasSize > ((PRInt32)dataSize * 3) / 4) { // be paranoid about having too few data
|
|
|
|
PR_Free(decodedData);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// Move the now-decoded data into the Handle.
|
|
|
|
// The size of the decoded data is 3/4 the size of the encoded data. See plbase64.h
|
|
|
|
Handle newHandle = nsnull;
|
|
|
|
if (::PtrToHand(decodedData, &newHandle, aliasSize) != noErr)
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
PR_Free(decodedData);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
Boolean changed;
|
|
|
|
FSRef resolvedFSRef;
|
|
|
|
OSErr err = ::FSResolveAlias(nsnull, (AliasHandle)newHandle, &resolvedFSRef, &changed);
|
|
|
|
|
|
|
|
rv = MacErrorMapper(err);
|
|
|
|
DisposeHandle(newHandle);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return InitWithFSRef(&resolvedFSRef);
|
|
|
|
#else
|
2002-04-27 05:33:09 +00:00
|
|
|
return InitWithNativePath(aPersistentDescriptor);
|
2010-07-26 03:49:28 +00:00
|
|
|
#endif
|
2000-07-17 15:03:05 +00:00
|
|
|
}
|
|
|
|
|
2001-01-30 05:02:48 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Reveal()
|
|
|
|
{
|
2007-11-26 23:55:34 +00:00
|
|
|
#ifdef MOZ_WIDGET_GTK2
|
2009-08-25 18:58:11 +00:00
|
|
|
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
|
|
|
nsCOMPtr<nsIGnomeVFSService> gnomevfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
|
|
|
|
if (!giovfs && !gnomevfs)
|
2007-11-26 23:55:34 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRBool isDirectory;
|
|
|
|
if (NS_FAILED(IsDirectory(&isDirectory)))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (isDirectory) {
|
2009-08-25 18:58:11 +00:00
|
|
|
if (giovfs)
|
|
|
|
return giovfs->ShowURIForInput(mPath);
|
|
|
|
else
|
|
|
|
/* Fallback to GnomeVFS */
|
|
|
|
return gnomevfs->ShowURIForInput(mPath);
|
2007-11-26 23:55:34 +00:00
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIFile> parentDir;
|
|
|
|
nsCAutoString dirPath;
|
|
|
|
if (NS_FAILED(GetParent(getter_AddRefs(parentDir))))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
if (NS_FAILED(parentDir->GetNativePath(dirPath)))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-08-25 18:58:11 +00:00
|
|
|
if (giovfs)
|
|
|
|
return giovfs->ShowURIForInput(dirPath);
|
|
|
|
else
|
|
|
|
return gnomevfs->ShowURIForInput(dirPath);
|
2007-11-26 23:55:34 +00:00
|
|
|
}
|
2010-07-22 03:25:24 +00:00
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
CFURLRef url;
|
|
|
|
if (NS_SUCCEEDED(GetCFURL(&url))) {
|
|
|
|
nsresult rv = CocoaFileUtils::RevealFileInFinder(url);
|
|
|
|
::CFRelease(url);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-11-26 23:55:34 +00:00
|
|
|
#else
|
2001-11-29 00:07:10 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2007-11-26 23:55:34 +00:00
|
|
|
#endif
|
2001-01-30 05:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Launch()
|
|
|
|
{
|
2007-11-26 23:55:34 +00:00
|
|
|
#ifdef MOZ_WIDGET_GTK2
|
2010-02-09 19:02:11 +00:00
|
|
|
#if (MOZ_PLATFORM_MAEMO==5)
|
2009-07-16 19:40:28 +00:00
|
|
|
const PRInt32 kHILDON_SUCCESS = 1;
|
|
|
|
DBusError err;
|
|
|
|
dbus_error_init(&err);
|
|
|
|
|
|
|
|
DBusConnection *connection = dbus_bus_get(DBUS_BUS_SESSION, &err);
|
|
|
|
if (dbus_error_is_set(&err)) {
|
|
|
|
dbus_error_free(&err);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull == connection)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (hildon_mime_open_file(connection, mPath.get()) != kHILDON_SUCCESS)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
2009-08-25 18:58:11 +00:00
|
|
|
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
|
|
|
nsCOMPtr<nsIGnomeVFSService> gnomevfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
|
|
|
|
if (giovfs) {
|
|
|
|
return giovfs->ShowURIForInput(mPath);
|
|
|
|
} else if (gnomevfs) {
|
|
|
|
/* GnomeVFS fallback */
|
|
|
|
return gnomevfs->ShowURIForInput(mPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-07-16 19:40:28 +00:00
|
|
|
#endif
|
2011-02-03 06:31:36 +00:00
|
|
|
#elif defined(MOZ_ENABLE_CONTENTACTION)
|
2010-07-30 19:46:20 +00:00
|
|
|
QUrl uri = QUrl::fromLocalFile(QString::fromUtf8(mPath.get()));
|
|
|
|
ContentAction::Action action =
|
|
|
|
ContentAction::Action::defaultActionForFile(uri);
|
|
|
|
|
|
|
|
if (action.isValid()) {
|
|
|
|
action.trigger();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-06-14 19:04:16 +00:00
|
|
|
#elif defined(ANDROID)
|
|
|
|
// Try to get a mimetype, if this fails just use the file uri alone
|
|
|
|
nsresult rv;
|
|
|
|
nsCAutoString type;
|
|
|
|
nsCOMPtr<nsIMIMEService> mimeService(do_GetService("@mozilla.org/mime;1", &rv));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = mimeService->GetTypeFromFile(this, type);
|
|
|
|
|
|
|
|
nsDependentCString fileUri = NS_LITERAL_CSTRING("file://");
|
|
|
|
fileUri.Append(mPath);
|
|
|
|
mozilla::AndroidBridge* bridge = mozilla::AndroidBridge::Bridge();
|
|
|
|
return bridge->OpenUriExternal(fileUri, type) ? NS_OK : NS_ERROR_FAILURE;
|
2010-07-22 03:25:24 +00:00
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
CFURLRef url;
|
|
|
|
if (NS_SUCCEEDED(GetCFURL(&url))) {
|
|
|
|
nsresult rv = CocoaFileUtils::OpenURL(url);
|
|
|
|
::CFRelease(url);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-11-26 23:55:34 +00:00
|
|
|
#else
|
2001-11-29 00:07:10 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2007-11-26 23:55:34 +00:00
|
|
|
#endif
|
2001-01-30 05:02:48 +00:00
|
|
|
}
|
|
|
|
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
nsresult
|
2002-04-27 05:33:09 +00:00
|
|
|
NS_NewNativeLocalFile(const nsACString &path, PRBool followSymlinks, nsILocalFile **result)
|
2000-01-24 21:28:28 +00:00
|
|
|
{
|
Fixes to use atomic rename(2) if possible in nsLocalFile::MoveTo (33098, r=?),
plus a bunch of other fixes and cleanups:
- Fix comment misstatements of fact in nsIFile.idl, improve style slightly.
- Fix typo in comment in nsILocalFile.idl.
- Avoid gratuitous nsCString and nsXPIDLCString copy-constructions, which
entail malloc'ing, in nsLocalFileUnix.cpp's CopyTo and GetParent methods.
But do use nsXPIDLCString instead of raw nsMemory::Alloc/Free.
- Get rid of unnecessary mLL_II2L and mLL_L2II macros, use "prlong.h" API only.
Also use the LL_* macros consistently in case a Unix lacking long long type
support wants to use this code.
* BTW, the "Date" methods should be renamed to use "Time" instead -- after all
PRTime is the type, and traditionally "time" refers to the time-number, a
scalar independent of one's position on the surface of the earth, while
"date" refers to a struct full of locale-specific information derived from
time and some "environment" variables such as DST. Can we rename these
nsIFile methods before Mozilla 0.9 / Netscape 6?
- Use CHECK_mPath consistently and first, before any assertions relating to
arguments (which logically come after the 'this' parameter CHECK_mPath is
making assertions about).
- Use nsCOMPtr for singly-inheriting implementations of XPCOM interfaces, to
avoid scary-when-scaled 0-refcnt instances from being handled (these all
got a ref via QI or equivalent soon enough, but you never know). This also
removed some naked deletes.
- Canonize all paths copied into mPath to lack trailing slashes, so we don't
need to strip trailing slashes elsewhere, in higher-frequency methods (you
set path less often than you get it or a substring of it).
- ssize_t for strlen return values.
- Since shaver used a function pointer to consolidate creat/mkdir logic, but
didn't fold the necessary close of the new fd returned by non-failing creat
into the pointed-at function, I did that.
- AppendRelativePath forbids .. as a component (bounded by / or beginning or
end of string on either side), not just in the middle of fragment (so that
foo..bar is not an illegal relative pathname -- it should not be). BTW,
what the heck is the difference between NS_ERROR_FILE_UNRECOGNIZED_PATH and
...INVALID_PATH?
- SetLeafName was overallocating the new pathname buffer by failing to subtract
the old leafname's length.
- CopyTo was failing to return an NSRESULT_FOR_ERRNO(), it just called that
macro on a line by itself -- eek! It also contained redundant if (newFD
== nsnull) {...} cleanup code, it did a useless PR_GetFileInfo call, and it
leaked FDs on read or write error.
- Implemented CopyToFollowingLinks as a forwarded call to CopyTo, Unix does
not support "copying" a symlink via normal file i/o. Should we instead
lstat in CopyTo and if a link is the source of the copy, do readlink and
then symlink?
- Fixed the readlink method (GetTarget) to null-terminate the link string in
the out parameter (readlink does not do that for you).
- Lots of little nsnull vs. NULL vs. 0, == and != applied to boolean or null
literals, white-space, indentation, bracing, comment, and sloppy code order
(e.g., declaring an initialized variable that's not used till after early
returns) fixes. Also invert some return logic so that NS_OK is the normal,
least indented, final return.
2000-09-19 00:22:41 +00:00
|
|
|
nsLocalFile *file = new nsLocalFile();
|
|
|
|
if (!file)
|
2000-01-24 21:28:28 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(file);
|
|
|
|
|
2010-07-22 03:25:24 +00:00
|
|
|
file->SetFollowLinks(followSymlinks);
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
if (!path.IsEmpty()) {
|
|
|
|
nsresult rv = file->InitWithNativePath(path);
|
2000-07-17 15:03:05 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(file);
|
|
|
|
return rv;
|
|
|
|
}
|
2000-01-24 21:28:28 +00:00
|
|
|
}
|
|
|
|
*result = file;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-04-27 05:33:09 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// unicode support
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define SET_UCS(func, ucsArg) \
|
|
|
|
{ \
|
2002-06-10 18:50:11 +00:00
|
|
|
nsCAutoString buf; \
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(ucsArg, buf); \
|
|
|
|
if (NS_FAILED(rv)) \
|
|
|
|
return rv; \
|
|
|
|
return (func)(buf); \
|
2002-04-27 05:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_UCS(func, ucsArg) \
|
|
|
|
{ \
|
|
|
|
nsCAutoString buf; \
|
|
|
|
nsresult rv = (func)(buf); \
|
|
|
|
if (NS_FAILED(rv)) return rv; \
|
2002-06-10 18:50:11 +00:00
|
|
|
return NS_CopyNativeToUnicode(buf, ucsArg); \
|
2002-04-27 05:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define SET_UCS_2ARGS_2(func, opaqueArg, ucsArg) \
|
|
|
|
{ \
|
2002-06-10 18:50:11 +00:00
|
|
|
nsCAutoString buf; \
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(ucsArg, buf); \
|
|
|
|
if (NS_FAILED(rv)) \
|
|
|
|
return rv; \
|
|
|
|
return (func)(opaqueArg, buf); \
|
2002-04-27 05:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unicode interface Wrapper
|
|
|
|
nsresult
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::InitWithPath(const nsAString &filePath)
|
2002-04-27 05:33:09 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
SET_UCS(InitWithNativePath, filePath);
|
2002-04-27 05:33:09 +00:00
|
|
|
}
|
|
|
|
nsresult
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::Append(const nsAString &node)
|
2002-04-27 05:33:09 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
SET_UCS(AppendNative, node);
|
2002-04-27 05:33:09 +00:00
|
|
|
}
|
|
|
|
nsresult
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::AppendRelativePath(const nsAString &node)
|
2002-04-27 05:33:09 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
SET_UCS(AppendRelativeNativePath, node);
|
2002-04-27 05:33:09 +00:00
|
|
|
}
|
|
|
|
nsresult
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::GetLeafName(nsAString &aLeafName)
|
2002-04-27 05:33:09 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
GET_UCS(GetNativeLeafName, aLeafName);
|
2002-04-27 05:33:09 +00:00
|
|
|
}
|
|
|
|
nsresult
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::SetLeafName(const nsAString &aLeafName)
|
2002-04-27 05:33:09 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
SET_UCS(SetNativeLeafName, aLeafName);
|
2002-04-27 05:33:09 +00:00
|
|
|
}
|
|
|
|
nsresult
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::GetPath(nsAString &_retval)
|
2002-04-27 05:33:09 +00:00
|
|
|
{
|
2002-06-10 18:50:11 +00:00
|
|
|
return NS_CopyNativeToUnicode(mPath, _retval);
|
2002-04-27 05:33:09 +00:00
|
|
|
}
|
|
|
|
nsresult
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::CopyTo(nsIFile *newParentDir, const nsAString &newName)
|
2002-04-27 05:33:09 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
SET_UCS_2ARGS_2(CopyToNative , newParentDir, newName);
|
2002-04-27 05:33:09 +00:00
|
|
|
}
|
|
|
|
nsresult
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::CopyToFollowingLinks(nsIFile *newParentDir, const nsAString &newName)
|
2002-04-27 05:33:09 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
SET_UCS_2ARGS_2(CopyToFollowingLinksNative , newParentDir, newName);
|
2002-04-27 05:33:09 +00:00
|
|
|
}
|
|
|
|
nsresult
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::MoveTo(nsIFile *newParentDir, const nsAString &newName)
|
2002-04-27 05:33:09 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
SET_UCS_2ARGS_2(MoveToNative, newParentDir, newName);
|
2002-04-27 05:33:09 +00:00
|
|
|
}
|
|
|
|
nsresult
|
2002-05-07 23:07:19 +00:00
|
|
|
nsLocalFile::GetTarget(nsAString &_retval)
|
2002-04-27 05:33:09 +00:00
|
|
|
{
|
2002-05-07 23:07:19 +00:00
|
|
|
GET_UCS(GetNativeTarget, _retval);
|
2002-04-27 05:33:09 +00:00
|
|
|
}
|
2005-11-18 14:18:49 +00:00
|
|
|
|
|
|
|
// nsIHashable
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::Equals(nsIHashable* aOther, PRBool *aResult)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> otherFile(do_QueryInterface(aOther));
|
|
|
|
if (!otherFile) {
|
|
|
|
*aResult = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Equals(otherFile, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetHashCode(PRUint32 *aResult)
|
|
|
|
{
|
|
|
|
*aResult = nsCRT::HashCode(mPath.get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
nsresult
|
2002-05-07 23:07:19 +00:00
|
|
|
NS_NewLocalFile(const nsAString &path, PRBool followLinks, nsILocalFile* *result)
|
2002-04-27 05:33:09 +00:00
|
|
|
{
|
2002-06-10 18:50:11 +00:00
|
|
|
nsCAutoString buf;
|
|
|
|
nsresult rv = NS_CopyUnicodeToNative(path, buf);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
return NS_NewNativeLocalFile(buf, followLinks, result);
|
2002-04-27 05:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// global init/shutdown
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLocalFile::GlobalInit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLocalFile::GlobalShutdown()
|
|
|
|
{
|
|
|
|
}
|
2010-07-22 03:25:24 +00:00
|
|
|
|
|
|
|
// nsILocalFileMac
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
|
|
|
|
static nsresult MacErrorMapper(OSErr inErr)
|
|
|
|
{
|
|
|
|
nsresult outErr;
|
|
|
|
|
|
|
|
switch (inErr)
|
|
|
|
{
|
|
|
|
case noErr:
|
|
|
|
outErr = NS_OK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fnfErr:
|
|
|
|
case afpObjectNotFound:
|
|
|
|
case afpDirNotFound:
|
|
|
|
outErr = NS_ERROR_FILE_NOT_FOUND;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dupFNErr:
|
|
|
|
case afpObjectExists:
|
|
|
|
outErr = NS_ERROR_FILE_ALREADY_EXISTS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dskFulErr:
|
|
|
|
case afpDiskFull:
|
|
|
|
outErr = NS_ERROR_FILE_DISK_FULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fLckdErr:
|
|
|
|
case afpVolLocked:
|
|
|
|
outErr = NS_ERROR_FILE_IS_LOCKED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case afpAccessDenied:
|
|
|
|
outErr = NS_ERROR_FILE_ACCESS_DENIED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case afpDirNotEmpty:
|
|
|
|
outErr = NS_ERROR_FILE_DIR_NOT_EMPTY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Can't find good map for some
|
|
|
|
case bdNamErr:
|
|
|
|
outErr = NS_ERROR_FAILURE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
outErr = NS_ERROR_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return outErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult CFStringReftoUTF8(CFStringRef aInStrRef, nsACString& aOutStr)
|
|
|
|
{
|
|
|
|
// first see if the conversion would succeed and find the length of the result
|
|
|
|
CFIndex usedBufLen, inStrLen = ::CFStringGetLength(aInStrRef);
|
|
|
|
CFIndex charsConverted = ::CFStringGetBytes(aInStrRef, CFRangeMake(0, inStrLen),
|
|
|
|
kCFStringEncodingUTF8, 0, PR_FALSE,
|
|
|
|
NULL, 0, &usedBufLen);
|
|
|
|
if (charsConverted == inStrLen) {
|
|
|
|
// all characters converted, do the actual conversion
|
|
|
|
aOutStr.SetLength(usedBufLen);
|
|
|
|
if (aOutStr.Length() != (unsigned int)usedBufLen)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
UInt8 *buffer = (UInt8*)aOutStr.BeginWriting();
|
|
|
|
::CFStringGetBytes(aInStrRef, CFRangeMake(0, inStrLen), kCFStringEncodingUTF8,
|
|
|
|
0, false, buffer, usedBufLen, &usedBufLen);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::InitWithCFURL(CFURLRef aCFURL)
|
|
|
|
{
|
|
|
|
UInt8 path[PATH_MAX];
|
|
|
|
if (::CFURLGetFileSystemRepresentation(aCFURL, false, path, PATH_MAX)) {
|
|
|
|
nsDependentCString nativePath((char*)path);
|
|
|
|
return InitWithNativePath(nativePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::InitWithFSRef(const FSRef *aFSRef)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aFSRef);
|
|
|
|
|
|
|
|
CFURLRef newURLRef = ::CFURLCreateFromFSRef(kCFAllocatorDefault, aFSRef);
|
|
|
|
if (newURLRef) {
|
|
|
|
nsresult rv = InitWithCFURL(newURLRef);
|
|
|
|
::CFRelease(newURLRef);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetCFURL(CFURLRef *_retval)
|
|
|
|
{
|
|
|
|
CHECK_mPath();
|
|
|
|
|
|
|
|
PRBool isDir;
|
|
|
|
IsDirectory(&isDir);
|
|
|
|
*_retval = ::CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
|
|
|
|
(UInt8*)mPath.get(),
|
|
|
|
mPath.Length(),
|
|
|
|
isDir);
|
|
|
|
|
|
|
|
return (*_retval ? NS_OK : NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetFSRef(FSRef *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
CFURLRef url = NULL;
|
|
|
|
if (NS_SUCCEEDED(GetCFURL(&url))) {
|
|
|
|
if (::CFURLGetFSRef(url, _retval)) {
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
::CFRelease(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetFSSpec(FSSpec *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
|
|
|
FSRef fsRef;
|
|
|
|
nsresult rv = GetFSRef(&fsRef);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNone, nsnull, nsnull, _retval, nsnull);
|
|
|
|
return MacErrorMapper(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetFileSizeWithResFork(PRInt64 *aFileSizeWithResFork)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aFileSizeWithResFork);
|
|
|
|
|
|
|
|
FSRef fsRef;
|
|
|
|
nsresult rv = GetFSRef(&fsRef);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
FSCatalogInfo catalogInfo;
|
|
|
|
OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoDataSizes + kFSCatInfoRsrcSizes,
|
|
|
|
&catalogInfo, nsnull, nsnull, nsnull);
|
|
|
|
if (err != noErr)
|
|
|
|
return MacErrorMapper(err);
|
|
|
|
|
|
|
|
*aFileSizeWithResFork = catalogInfo.dataLogicalSize + catalogInfo.rsrcLogicalSize;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetFileType(OSType *aFileType)
|
|
|
|
{
|
|
|
|
CFURLRef url;
|
|
|
|
if (NS_SUCCEEDED(GetCFURL(&url))) {
|
|
|
|
nsresult rv = CocoaFileUtils::GetFileTypeCode(url, aFileType);
|
|
|
|
::CFRelease(url);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::SetFileType(OSType aFileType)
|
|
|
|
{
|
|
|
|
CFURLRef url;
|
|
|
|
if (NS_SUCCEEDED(GetCFURL(&url))) {
|
|
|
|
nsresult rv = CocoaFileUtils::SetFileTypeCode(url, aFileType);
|
|
|
|
::CFRelease(url);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetFileCreator(OSType *aFileCreator)
|
|
|
|
{
|
|
|
|
CFURLRef url;
|
|
|
|
if (NS_SUCCEEDED(GetCFURL(&url))) {
|
|
|
|
nsresult rv = CocoaFileUtils::GetFileCreatorCode(url, aFileCreator);
|
|
|
|
::CFRelease(url);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::SetFileCreator(OSType aFileCreator)
|
|
|
|
{
|
|
|
|
CFURLRef url;
|
|
|
|
if (NS_SUCCEEDED(GetCFURL(&url))) {
|
|
|
|
nsresult rv = CocoaFileUtils::SetFileCreatorCode(url, aFileCreator);
|
|
|
|
::CFRelease(url);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::LaunchWithDoc(nsILocalFile *aDocToLoad, PRBool aLaunchInBackground)
|
|
|
|
{
|
|
|
|
PRBool isExecutable;
|
|
|
|
nsresult rv = IsExecutable(&isExecutable);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
if (!isExecutable)
|
|
|
|
return NS_ERROR_FILE_EXECUTION_FAILED;
|
|
|
|
|
|
|
|
FSRef appFSRef, docFSRef;
|
|
|
|
rv = GetFSRef(&appFSRef);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (aDocToLoad) {
|
|
|
|
nsCOMPtr<nsILocalFileMac> macDoc = do_QueryInterface(aDocToLoad);
|
|
|
|
rv = macDoc->GetFSRef(&docFSRef);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
LSLaunchFlags theLaunchFlags = kLSLaunchDefaults;
|
|
|
|
LSLaunchFSRefSpec thelaunchSpec;
|
|
|
|
|
|
|
|
if (aLaunchInBackground)
|
|
|
|
theLaunchFlags |= kLSLaunchDontSwitch;
|
|
|
|
memset(&thelaunchSpec, 0, sizeof(LSLaunchFSRefSpec));
|
|
|
|
|
|
|
|
thelaunchSpec.appRef = &appFSRef;
|
|
|
|
if (aDocToLoad) {
|
|
|
|
thelaunchSpec.numDocs = 1;
|
|
|
|
thelaunchSpec.itemRefs = &docFSRef;
|
|
|
|
}
|
|
|
|
thelaunchSpec.launchFlags = theLaunchFlags;
|
|
|
|
|
|
|
|
OSErr err = ::LSOpenFromRefSpec(&thelaunchSpec, NULL);
|
|
|
|
if (err != noErr)
|
|
|
|
return MacErrorMapper(err);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::OpenDocWithApp(nsILocalFile *aAppToOpenWith, PRBool aLaunchInBackground)
|
|
|
|
{
|
|
|
|
FSRef docFSRef;
|
|
|
|
nsresult rv = GetFSRef(&docFSRef);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!aAppToOpenWith) {
|
|
|
|
OSErr err = ::LSOpenFSRef(&docFSRef, NULL);
|
|
|
|
return MacErrorMapper(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFileMac> appFileMac = do_QueryInterface(aAppToOpenWith, &rv);
|
|
|
|
if (!appFileMac)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
PRBool isExecutable;
|
|
|
|
rv = appFileMac->IsExecutable(&isExecutable);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
if (!isExecutable)
|
|
|
|
return NS_ERROR_FILE_EXECUTION_FAILED;
|
|
|
|
|
|
|
|
FSRef appFSRef;
|
|
|
|
rv = appFileMac->GetFSRef(&appFSRef);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
LSLaunchFlags theLaunchFlags = kLSLaunchDefaults;
|
|
|
|
LSLaunchFSRefSpec thelaunchSpec;
|
|
|
|
|
|
|
|
if (aLaunchInBackground)
|
|
|
|
theLaunchFlags |= kLSLaunchDontSwitch;
|
|
|
|
memset(&thelaunchSpec, 0, sizeof(LSLaunchFSRefSpec));
|
|
|
|
|
|
|
|
thelaunchSpec.appRef = &appFSRef;
|
|
|
|
thelaunchSpec.numDocs = 1;
|
|
|
|
thelaunchSpec.itemRefs = &docFSRef;
|
|
|
|
thelaunchSpec.launchFlags = theLaunchFlags;
|
|
|
|
|
|
|
|
OSErr err = ::LSOpenFromRefSpec(&thelaunchSpec, NULL);
|
|
|
|
if (err != noErr)
|
|
|
|
return MacErrorMapper(err);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::IsPackage(PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
|
|
|
CFURLRef url;
|
|
|
|
nsresult rv = GetCFURL(&url);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
LSItemInfoRecord info;
|
|
|
|
OSStatus status = ::LSCopyItemInfoForURL(url, kLSRequestBasicFlagsOnly, &info);
|
|
|
|
|
|
|
|
::CFRelease(url);
|
|
|
|
|
|
|
|
if (status != noErr) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*_retval = !!(info.flags & kLSItemInfoIsPackage);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetBundleDisplayName(nsAString& outBundleName)
|
|
|
|
{
|
|
|
|
PRBool isPackage = PR_FALSE;
|
|
|
|
nsresult rv = IsPackage(&isPackage);
|
|
|
|
if (NS_FAILED(rv) || !isPackage)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsAutoString name;
|
|
|
|
rv = GetLeafName(name);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
PRInt32 length = name.Length();
|
|
|
|
if (Substring(name, length - 4, length).EqualsLiteral(".app")) {
|
|
|
|
// 4 characters in ".app"
|
|
|
|
outBundleName = Substring(name, 0, length - 4);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
outBundleName = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalFile::GetBundleIdentifier(nsACString& outBundleIdentifier)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
CFURLRef urlRef;
|
|
|
|
if (NS_SUCCEEDED(GetCFURL(&urlRef))) {
|
|
|
|
CFBundleRef bundle = ::CFBundleCreate(NULL, urlRef);
|
|
|
|
if (bundle) {
|
|
|
|
CFStringRef bundleIdentifier = ::CFBundleGetIdentifier(bundle);
|
|
|
|
if (bundleIdentifier)
|
|
|
|
rv = CFStringReftoUTF8(bundleIdentifier, outBundleIdentifier);
|
|
|
|
::CFRelease(bundle);
|
|
|
|
}
|
|
|
|
::CFRelease(urlRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsLocalFile::InitWithFile(nsILocalFile *aFile)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aFile);
|
|
|
|
|
|
|
|
nsCAutoString nativePath;
|
|
|
|
nsresult rv = aFile->GetNativePath(nativePath);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return InitWithNativePath(nativePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewLocalFileWithFSRef(const FSRef* aFSRef, PRBool aFollowLinks, nsILocalFileMac** result)
|
|
|
|
{
|
|
|
|
nsLocalFile* file = new nsLocalFile();
|
|
|
|
if (file == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(file);
|
|
|
|
|
|
|
|
file->SetFollowLinks(aFollowLinks);
|
|
|
|
|
|
|
|
nsresult rv = file->InitWithFSRef(aFSRef);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(file);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
*result = file;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewLocalFileWithCFURL(const CFURLRef aURL, PRBool aFollowLinks, nsILocalFileMac** result)
|
|
|
|
{
|
|
|
|
nsLocalFile* file = new nsLocalFile();
|
|
|
|
if (!file)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(file);
|
|
|
|
|
|
|
|
file->SetFollowLinks(aFollowLinks);
|
|
|
|
|
|
|
|
nsresult rv = file->InitWithCFURL(aURL);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(file);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
*result = file;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|