From 528cb517acc0c9de38afc8ed44b5b3436be0698b Mon Sep 17 00:00:00 2001 From: "shaver%netscape.com" Date: Mon, 29 Nov 1999 14:55:03 +0000 Subject: [PATCH] - Portions of nsIFile and nsIDirectoryEnumerator implementations for Unix. - Various missing-newline-at-end-of-file fixes from Andrew Taylor . - Fixed case in nsIDirectoryEnumerator.idl - Added |normalize()|, |truncate()| and |target|, |isSpecial()| to nsIFile.idl - Changed |isExists()| to |exists()|, |fileName| to |leafName|, |isEqual()| to |equals| and added |in boolean recur| to |isContainedIn()|. - Corrected widespread misspelling of |NS_ERROR_FILE_UNRECOGNIZED_PATH|. - Partially updated Windows code to track changes. Partially addresses 17948, r=dougt --- xpcom/io/nsFileUtils.cpp | 2 +- xpcom/io/nsFileUtils.h | 38 -------------------- xpcom/io/nsIDirEnumeratorImpl.h | 40 --------------------- xpcom/io/nsIDirEnumeratorImplUnix.cpp | 0 xpcom/io/nsIDirEnumeratorImplUnix.h | 0 xpcom/io/nsIDirectoryEnumerator.idl | 38 -------------------- xpcom/io/nsIFile.idl | 51 ++++++++++++++++++--------- xpcom/io/nsIFileImpl.h | 40 --------------------- xpcom/io/nsIFileImplUnix.cpp | 0 xpcom/io/nsIFileImplUnix.h | 0 xpcom/io/nsIFileImplWin.cpp | 16 ++++----- 11 files changed, 44 insertions(+), 181 deletions(-) create mode 100644 xpcom/io/nsIDirEnumeratorImplUnix.cpp create mode 100644 xpcom/io/nsIDirEnumeratorImplUnix.h create mode 100644 xpcom/io/nsIFileImplUnix.cpp create mode 100644 xpcom/io/nsIFileImplUnix.h diff --git a/xpcom/io/nsFileUtils.cpp b/xpcom/io/nsFileUtils.cpp index 32b300447ac..a945695f454 100644 --- a/xpcom/io/nsFileUtils.cpp +++ b/xpcom/io/nsFileUtils.cpp @@ -28,4 +28,4 @@ NS_NewDirectoryEnumerator(nsIFile* parent, PRBool resolveSymlinks, nsIDirectoryE (*enumerator)->Init(parent, resolveSymlinks); } return rv; -} \ No newline at end of file +} diff --git a/xpcom/io/nsFileUtils.h b/xpcom/io/nsFileUtils.h index b707404d16d..e69de29bb2d 100644 --- a/xpcom/io/nsFileUtils.h +++ b/xpcom/io/nsFileUtils.h @@ -1,38 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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. - * - * 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 Netscape are - * Copyright (C) 1998-1999 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Doug Turner - */ - -#ifndef _NSIFILEUTILS_H_ -#define _NSIFILEUTILS_H_ - -#include "nscore.h" - -#include "nsIFile.h" -#include "nsIDirectoryEnumerator.h" - -// Helper function(s) -nsresult NS_COM NS_NewFile(nsIFile** file); - -nsresult NS_COM NS_NewDirectoryEnumerator(nsIFile* parent, PRBool resolveSymlinks, nsIDirectoryEnumerator** enumerator); - -#endif \ No newline at end of file diff --git a/xpcom/io/nsIDirEnumeratorImpl.h b/xpcom/io/nsIDirEnumeratorImpl.h index ef9e7c80041..e69de29bb2d 100644 --- a/xpcom/io/nsIDirEnumeratorImpl.h +++ b/xpcom/io/nsIDirEnumeratorImpl.h @@ -1,40 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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. - * - * 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 Netscape are - * Copyright (C) 1998-1999 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Doug Turner - */ - -#ifndef _NSIDIRENUMERATORIMPL_H_ -#define _NSIDIRENUMERATORIMPL_H_ - -#define NS_IDIRECTORYENUMERATOR_CID {0xe67dcbe0, 0x6a21, 0x11d3, {0x8c, 0x51, 0x00, 0x60, 0x97, 0x92, 0x27, 0x8c}} - -// nsXPComInit needs to know about how we are implmented, -// so here we will export it. Other users should not depend -// on this - -#ifdef XP_PC -#include "nsIDirEnumeratorImplWin.h" -#else -#error NOT_IMPLEMENTED -#endif - -#endif \ No newline at end of file diff --git a/xpcom/io/nsIDirEnumeratorImplUnix.cpp b/xpcom/io/nsIDirEnumeratorImplUnix.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/xpcom/io/nsIDirEnumeratorImplUnix.h b/xpcom/io/nsIDirEnumeratorImplUnix.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/xpcom/io/nsIDirectoryEnumerator.idl b/xpcom/io/nsIDirectoryEnumerator.idl index db4ed4a2c97..e69de29bb2d 100644 --- a/xpcom/io/nsIDirectoryEnumerator.idl +++ b/xpcom/io/nsIDirectoryEnumerator.idl @@ -1,38 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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. - * - * 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 Netscape are - * Copyright (C) 1998-1999 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Doug Turner - */ - -#include "nsIEnumerator.idl" - -interface nsIFile; - -[scriptable, uuid(D7BEA930-59D7-11d3-8C46-00609792278C)] -interface nsIDirectoryEnumerator : nsISimpleEnumerator -{ - void Init(in nsIFile parent, in boolean resolveSymlinks); -}; - -%{C++ -#define NS_DIRECTORY_ENUMERATOR_PROGID "component://netscape/file/enumerator" -#define NS_DIRECTORY_ENUMERATOR_CLASS "Directory Enumerator" -%} \ No newline at end of file diff --git a/xpcom/io/nsIFile.idl b/xpcom/io/nsIFile.idl index dd6b85c02e0..945abd2d233 100644 --- a/xpcom/io/nsIFile.idl +++ b/xpcom/io/nsIFile.idl @@ -141,6 +141,11 @@ interface nsIFile : nsISupports void appendPath([const] in string relativePath); + /** + * Normalize the pathName (e.g. removing .. and . components on Unix). + */ + void normalize(); + /** * create * @@ -166,10 +171,9 @@ interface nsIFile : nsISupports /** - * Accessor to the file name (the leaf name not the full file path) - * of the file itself. + * Accessor to the leaf name of the file itself. */ - readonly attribute string fileName; + readonly attribute string leafName; /** * getPath @@ -275,50 +279,65 @@ interface nsIFile : nsISupports */ void delete(in boolean recursive); + /** + * Truncate the file to the given length. + */ + void truncate(in unsigned long length); + /** * Attributes of nsIFile. */ attribute unsigned long lastModificationDate; - attribute unsigned long lastModificationDateOfLink; - attribute unsigned long permissions; - attribute unsigned long permissionsOfLink; - readonly attribute unsigned long fileSize; + + attribute unsigned long lastModificationDateOfLink; + attribute unsigned long permissionsOfLink; + /* should we make this writable and have it map to truncate? */ readonly attribute unsigned long fileSizeOfLink; - + /** + * Find out what the symlink points at. Will give error + * (NS_ERROR_FILE_INVALID_PATH) if not a symlink. + */ + readonly attribute string target; readonly attribute long long diskSpaceAvailable; // maybe we should put this somewhere else. /** * Parent will be nsnull when this is at the top of the volume. */ - readonly attribute nsIFile parent; + readonly attribute nsIFile parent; - boolean isExists(); - boolean isWriteable(); + boolean exists(); + boolean isWritable(); boolean isReadable(); + boolean isExecutable(); + boolean isHidden(); boolean isDirectory(); boolean isFile(); - boolean isHidden(); boolean isSymlink(); + /** + * Not a regular file, not a directory, not a symlink. + */ + boolean isSpecial(); /** * Will determine if the inFile equals this. */ - boolean isEqual(in nsIFile inFile); + boolean equals(in nsIFile inFile); /** - * Will determine the file is a sibling of the parameter inFile. + * Will determine the file is a descendant of the parameter inFile. + * If |recur| is true, it will descend subdirectories looking for */ - boolean isContainedIn(in nsIFile inFile); + boolean isContainedIn(in nsIFile inFile, in boolean recur); }; %{C++ #define NS_FILE_PROGID "component://netscape/file" #define NS_FILE_CLASSNAME "File Specification" -#define NS_ERROR_FILE_UNRECONGNIZED_PATH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 1) +#define NS_ERROR_FILE_UNRECOGNIZED_PATH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 1) #define NS_ERROR_FILE_UNRESOLVABLE_SYMLINK NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 2) #define NS_ERROR_FILE_EXECUTION_FAILED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 3) #define NS_ERROR_FILE_UNKNOWN_TYPE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 4) diff --git a/xpcom/io/nsIFileImpl.h b/xpcom/io/nsIFileImpl.h index fb29cf11956..e69de29bb2d 100644 --- a/xpcom/io/nsIFileImpl.h +++ b/xpcom/io/nsIFileImpl.h @@ -1,40 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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. - * - * 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 Netscape are - * Copyright (C) 1998-1999 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Doug Turner - */ - -#ifndef _NSIFILEIMPL_H_ -#define _NSIFILEIMPL_H_ - -#define NS_IFILEIMPL_CID {0x2e23e220, 0x60be, 0x11d3, {0x8c, 0x4a, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}} - -// nsXPComInit needs to know about how we are implmented, -// so here we will export it. Other users should not depend -// on this. - -#ifdef XP_PC -#include "nsIFileImplWin.h" -#else -#error NOT_IMPLEMENTED -#endif - -#endif \ No newline at end of file diff --git a/xpcom/io/nsIFileImplUnix.cpp b/xpcom/io/nsIFileImplUnix.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/xpcom/io/nsIFileImplUnix.h b/xpcom/io/nsIFileImplUnix.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/xpcom/io/nsIFileImplWin.cpp b/xpcom/io/nsIFileImplWin.cpp index 175520370e8..c30441b849a 100644 --- a/xpcom/io/nsIFileImplWin.cpp +++ b/xpcom/io/nsIFileImplWin.cpp @@ -422,9 +422,9 @@ nsIFileImpl::AppendPath(const char *node) } NS_IMETHODIMP -nsIFileImpl::GetFileName(char * *aFileName) +nsIFileImpl::GetLeafName(char * *aLeafName) { - NS_ENSURE_ARG_POINTER(aFileName); + NS_ENSURE_ARG_POINTER(aLeafName); const char* temp = mWorkingPath.GetBuffer(); if(temp == nsnull) @@ -438,7 +438,7 @@ nsIFileImpl::GetFileName(char * *aFileName) else leaf++; - *aFileName = (char*) nsAllocator::Clone(leaf, strlen(leaf)+1); + *aLeafName = (char*) nsAllocator::Clone(leaf, strlen(leaf)+1); return NS_OK; } @@ -873,7 +873,7 @@ nsIFileImpl::GetParent(nsIFile * *aParent) return NS_OK; } NS_IMETHODIMP -nsIFileImpl::IsExists(PRBool *_retval) +nsIFileImpl::Exists(PRBool *_retval) { NS_ENSURE_ARG(_retval); @@ -889,7 +889,7 @@ nsIFileImpl::IsExists(PRBool *_retval) } NS_IMETHODIMP -nsIFileImpl::IsWriteable(PRBool *_retval) +nsIFileImpl::IsWritable(PRBool *_retval) { NS_ENSURE_ARG(_retval); return NS_ERROR_NOT_IMPLEMENTED; @@ -962,7 +962,7 @@ nsIFileImpl::IsSymlink(PRBool *_retval) } NS_IMETHODIMP -nsIFileImpl::IsEqual(nsIFile *inFile, PRBool *_retval) +nsIFileImpl::Equals(nsIFile *inFile, PRBool *_retval) { NS_ENSURE_ARG(inFile); NS_ENSURE_ARG(_retval); @@ -985,7 +985,7 @@ nsIFileImpl::IsEqual(nsIFile *inFile, PRBool *_retval) } NS_IMETHODIMP -nsIFileImpl::IsContainedIn(nsIFile *inFile, PRBool *_retval) +nsIFileImpl::IsContainedIn(nsIFile *inFile, PRBool recur, PRBool *_retval) { return NS_ERROR_NOT_IMPLEMENTED; -} \ No newline at end of file +}