1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/io/nsIFile.idl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,487 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsISupports.idl" 1.10 + 1.11 +%{C++ 1.12 +struct PRFileDesc; 1.13 +struct PRLibrary; 1.14 +#include <stdio.h> 1.15 +%} 1.16 + 1.17 +[ptr] native PRFileDescStar(PRFileDesc); 1.18 +[ptr] native PRLibraryStar(PRLibrary); 1.19 +[ptr] native FILE(FILE); 1.20 + 1.21 +interface nsISimpleEnumerator; 1.22 + 1.23 +/** 1.24 + * An nsIFile is an abstract representation of a filename. It manages 1.25 + * filename encoding issues, pathname component separators ('/' vs. '\\' 1.26 + * vs. ':') and weird stuff like differing volumes with identical names, as 1.27 + * on pre-Darwin Macintoshes. 1.28 + * 1.29 + * This file has long introduced itself to new hackers with this opening 1.30 + * paragraph: 1.31 + * 1.32 + * This is the only correct cross-platform way to specify a file. 1.33 + * Strings are not such a way. If you grew up on windows or unix, you 1.34 + * may think they are. Welcome to reality. 1.35 + * 1.36 + * While taking the pose struck here to heart would be uncalled for, one 1.37 + * may safely conclude that writing cross-platform code is an embittering 1.38 + * experience. 1.39 + * 1.40 + * All methods with string parameters have two forms. The preferred 1.41 + * form operates on UCS-2 encoded characters strings. An alternate 1.42 + * form operates on characters strings encoded in the "native" charset. 1.43 + * 1.44 + * A string containing characters encoded in the native charset cannot 1.45 + * be safely passed to javascript via xpconnect. Therefore, the "native 1.46 + * methods" are not scriptable. 1.47 + */ 1.48 +[scriptable, uuid(a99a6a06-f90d-4659-8fce-c2f87feb1167), builtinclass] 1.49 +interface nsIFile : nsISupports 1.50 +{ 1.51 + /** 1.52 + * Create Types 1.53 + * 1.54 + * NORMAL_FILE_TYPE - A normal file. 1.55 + * DIRECTORY_TYPE - A directory/folder. 1.56 + */ 1.57 + const unsigned long NORMAL_FILE_TYPE = 0; 1.58 + const unsigned long DIRECTORY_TYPE = 1; 1.59 + 1.60 + /** 1.61 + * append[Native] 1.62 + * 1.63 + * This function is used for constructing a descendent of the 1.64 + * current nsIFile. 1.65 + * 1.66 + * @param node 1.67 + * A string which is intended to be a child node of the nsIFile. 1.68 + * For the |appendNative| method, the node must be in the native 1.69 + * filesystem charset. 1.70 + */ 1.71 + void append(in AString node); 1.72 + [noscript] void appendNative(in ACString node); 1.73 + 1.74 + /** 1.75 + * Normalize the pathName (e.g. removing .. and . components on Unix). 1.76 + */ 1.77 + void normalize(); 1.78 + 1.79 + /** 1.80 + * create 1.81 + * 1.82 + * This function will create a new file or directory in the 1.83 + * file system. Any nodes that have not been created or 1.84 + * resolved, will be. If the file or directory already 1.85 + * exists create() will return NS_ERROR_FILE_ALREADY_EXISTS. 1.86 + * 1.87 + * @param type 1.88 + * This specifies the type of file system object 1.89 + * to be made. The only two types at this time 1.90 + * are file and directory which are defined above. 1.91 + * If the type is unrecongnized, we will return an 1.92 + * error (NS_ERROR_FILE_UNKNOWN_TYPE). 1.93 + * 1.94 + * @param permissions 1.95 + * The unix style octal permissions. This may 1.96 + * be ignored on systems that do not need to do 1.97 + * permissions. 1.98 + */ 1.99 + void create(in unsigned long type, in unsigned long permissions); 1.100 + 1.101 + /** 1.102 + * Accessor to the leaf name of the file itself. 1.103 + * For the |nativeLeafName| method, the nativeLeafName must 1.104 + * be in the native filesystem charset. 1.105 + */ 1.106 + attribute AString leafName; 1.107 + [noscript] attribute ACString nativeLeafName; 1.108 + 1.109 + /** 1.110 + * copyTo[Native] 1.111 + * 1.112 + * This will copy this file to the specified newParentDir. 1.113 + * If a newName is specified, the file will be renamed. 1.114 + * If 'this' is not created we will return an error 1.115 + * (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST). 1.116 + * 1.117 + * copyTo may fail if the file already exists in the destination 1.118 + * directory. 1.119 + * 1.120 + * copyTo will NOT resolve aliases/shortcuts during the copy. 1.121 + * 1.122 + * @param newParentDir 1.123 + * This param is the destination directory. If the 1.124 + * newParentDir is null, copyTo() will use the parent 1.125 + * directory of this file. If the newParentDir is not 1.126 + * empty and is not a directory, an error will be 1.127 + * returned (NS_ERROR_FILE_DESTINATION_NOT_DIR). For the 1.128 + * |CopyToNative| method, the newName must be in the 1.129 + * native filesystem charset. 1.130 + * 1.131 + * @param newName 1.132 + * This param allows you to specify a new name for 1.133 + * the file to be copied. This param may be empty, in 1.134 + * which case the current leaf name will be used. 1.135 + */ 1.136 + void copyTo(in nsIFile newParentDir, in AString newName); 1.137 + [noscript] void CopyToNative(in nsIFile newParentDir, in ACString newName); 1.138 + 1.139 + /** 1.140 + * copyToFollowingLinks[Native] 1.141 + * 1.142 + * This function is identical to copyTo with the exception that, 1.143 + * as the name implies, it follows symbolic links. The XP_UNIX 1.144 + * implementation always follow symbolic links when copying. For 1.145 + * the |CopyToFollowingLinks| method, the newName must be in the 1.146 + * native filesystem charset. 1.147 + */ 1.148 + void copyToFollowingLinks(in nsIFile newParentDir, in AString newName); 1.149 + [noscript] void copyToFollowingLinksNative(in nsIFile newParentDir, in ACString newName); 1.150 + 1.151 + /** 1.152 + * moveTo[Native] 1.153 + * 1.154 + * A method to move this file or directory to newParentDir. 1.155 + * If a newName is specified, the file or directory will be renamed. 1.156 + * If 'this' is not created we will return an error 1.157 + * (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST). 1.158 + * If 'this' is a file, and the destination file already exists, moveTo 1.159 + * will replace the old file. 1.160 + * This object is updated to refer to the new file. 1.161 + * 1.162 + * moveTo will NOT resolve aliases/shortcuts during the copy. 1.163 + * moveTo will do the right thing and allow copies across volumes. 1.164 + * moveTo will return an error (NS_ERROR_FILE_DIR_NOT_EMPTY) if 'this' is 1.165 + * a directory and the destination directory is not empty. 1.166 + * moveTo will return an error (NS_ERROR_FILE_ACCESS_DENIED) if 'this' is 1.167 + * a directory and the destination directory is not writable. 1.168 + * 1.169 + * @param newParentDir 1.170 + * This param is the destination directory. If the 1.171 + * newParentDir is empty, moveTo() will rename the file 1.172 + * within its current directory. If the newParentDir is 1.173 + * not empty and does not name a directory, an error will 1.174 + * be returned (NS_ERROR_FILE_DESTINATION_NOT_DIR). For 1.175 + * the |moveToNative| method, the newName must be in the 1.176 + * native filesystem charset. 1.177 + * 1.178 + * @param newName 1.179 + * This param allows you to specify a new name for 1.180 + * the file to be moved. This param may be empty, in 1.181 + * which case the current leaf name will be used. 1.182 + */ 1.183 + void moveTo(in nsIFile newParentDir, in AString newName); 1.184 + [noscript] void moveToNative(in nsIFile newParentDir, in ACString newName); 1.185 + 1.186 + /** 1.187 + * renameTo 1.188 + * 1.189 + * This method is identical to moveTo except that if this file or directory 1.190 + * is moved to a a different volume, it fails and returns an error 1.191 + * (NS_ERROR_FILE_ACCESS_DENIED). 1.192 + * This object will still point to the old location after renaming. 1.193 + */ 1.194 + void renameTo(in nsIFile newParentDir, in AString newName); 1.195 + 1.196 + /** 1.197 + * This will try to delete this file. The 'recursive' flag 1.198 + * must be PR_TRUE to delete directories which are not empty. 1.199 + * 1.200 + * This will not resolve any symlinks. 1.201 + */ 1.202 + void remove(in boolean recursive); 1.203 + 1.204 + /** 1.205 + * Attributes of nsIFile. 1.206 + */ 1.207 + 1.208 + attribute unsigned long permissions; 1.209 + attribute unsigned long permissionsOfLink; 1.210 + 1.211 + /** 1.212 + * File Times are to be in milliseconds from 1.213 + * midnight (00:00:00), January 1, 1970 Greenwich Mean 1.214 + * Time (GMT). 1.215 + */ 1.216 + attribute PRTime lastModifiedTime; 1.217 + attribute PRTime lastModifiedTimeOfLink; 1.218 + 1.219 + /** 1.220 + * WARNING! On the Mac, getting/setting the file size with nsIFile 1.221 + * only deals with the size of the data fork. If you need to 1.222 + * know the size of the combined data and resource forks use the 1.223 + * GetFileSizeWithResFork() method defined on nsILocalFileMac. 1.224 + */ 1.225 + attribute int64_t fileSize; 1.226 + readonly attribute int64_t fileSizeOfLink; 1.227 + 1.228 + /** 1.229 + * target & path 1.230 + * 1.231 + * Accessor to the string path. The native version of these 1.232 + * strings are not guaranteed to be a usable path to pass to 1.233 + * NSPR or the C stdlib. There are problems that affect 1.234 + * platforms on which a path does not fully specify a file 1.235 + * because two volumes can have the same name (e.g., mac). 1.236 + * This is solved by holding "private", native data in the 1.237 + * nsIFile implementation. This native data is lost when 1.238 + * you convert to a string. 1.239 + * 1.240 + * DO NOT PASS TO USE WITH NSPR OR STDLIB! 1.241 + * 1.242 + * target 1.243 + * Find out what the symlink points at. Will give error 1.244 + * (NS_ERROR_FILE_INVALID_PATH) if not a symlink. 1.245 + * 1.246 + * path 1.247 + * Find out what the nsIFile points at. 1.248 + * 1.249 + * Note that the ACString attributes are returned in the 1.250 + * native filesystem charset. 1.251 + * 1.252 + */ 1.253 + readonly attribute AString target; 1.254 + [noscript] readonly attribute ACString nativeTarget; 1.255 + readonly attribute AString path; 1.256 + [noscript] readonly attribute ACString nativePath; 1.257 + 1.258 + boolean exists(); 1.259 + boolean isWritable(); 1.260 + boolean isReadable(); 1.261 + boolean isExecutable(); 1.262 + boolean isHidden(); 1.263 + boolean isDirectory(); 1.264 + boolean isFile(); 1.265 + boolean isSymlink(); 1.266 + /** 1.267 + * Not a regular file, not a directory, not a symlink. 1.268 + */ 1.269 + boolean isSpecial(); 1.270 + 1.271 + /** 1.272 + * createUnique 1.273 + * 1.274 + * This function will create a new file or directory in the 1.275 + * file system. Any nodes that have not been created or 1.276 + * resolved, will be. If this file already exists, we try 1.277 + * variations on the leaf name "suggestedName" until we find 1.278 + * one that did not already exist. 1.279 + * 1.280 + * If the search for nonexistent files takes too long 1.281 + * (thousands of the variants already exist), we give up and 1.282 + * return NS_ERROR_FILE_TOO_BIG. 1.283 + * 1.284 + * @param type 1.285 + * This specifies the type of file system object 1.286 + * to be made. The only two types at this time 1.287 + * are file and directory which are defined above. 1.288 + * If the type is unrecongnized, we will return an 1.289 + * error (NS_ERROR_FILE_UNKNOWN_TYPE). 1.290 + * 1.291 + * @param permissions 1.292 + * The unix style octal permissions. This may 1.293 + * be ignored on systems that do not need to do 1.294 + * permissions. 1.295 + */ 1.296 + void createUnique(in unsigned long type, in unsigned long permissions); 1.297 + 1.298 + /** 1.299 + * clone() 1.300 + * 1.301 + * This function will allocate and initialize a nsIFile object to the 1.302 + * exact location of the |this| nsIFile. 1.303 + * 1.304 + * @param file 1.305 + * A nsIFile which this object will be initialize 1.306 + * with. 1.307 + * 1.308 + */ 1.309 + nsIFile clone(); 1.310 + 1.311 + /** 1.312 + * Will determine if the inFile equals this. 1.313 + */ 1.314 + boolean equals(in nsIFile inFile); 1.315 + 1.316 + /** 1.317 + * Will determine if inFile is a descendant of this file 1.318 + * If |recur| is true, look in subdirectories too 1.319 + */ 1.320 + boolean contains(in nsIFile inFile, in boolean recur); 1.321 + 1.322 + /** 1.323 + * Parent will be null when this is at the top of the volume. 1.324 + */ 1.325 + readonly attribute nsIFile parent; 1.326 + 1.327 + /** 1.328 + * Returns an enumeration of the elements in a directory. Each 1.329 + * element in the enumeration is an nsIFile. 1.330 + * 1.331 + * @throws NS_ERROR_FILE_NOT_DIRECTORY if the current nsIFile does 1.332 + * not specify a directory. 1.333 + */ 1.334 + readonly attribute nsISimpleEnumerator directoryEntries; 1.335 + 1.336 + /** 1.337 + * initWith[Native]Path 1.338 + * 1.339 + * This function will initialize the nsIFile object. Any 1.340 + * internal state information will be reset. 1.341 + * 1.342 + * @param filePath 1.343 + * A string which specifies a full file path to a 1.344 + * location. Relative paths will be treated as an 1.345 + * error (NS_ERROR_FILE_UNRECOGNIZED_PATH). For 1.346 + * initWithNativePath, the filePath must be in the native 1.347 + * filesystem charset. 1.348 + */ 1.349 + void initWithPath(in AString filePath); 1.350 + [noscript] void initWithNativePath(in ACString filePath); 1.351 + 1.352 + /** 1.353 + * initWithFile 1.354 + * 1.355 + * Initialize this object with another file 1.356 + * 1.357 + * @param aFile 1.358 + * the file this becomes equivalent to 1.359 + */ 1.360 + void initWithFile(in nsIFile aFile); 1.361 + 1.362 + /** 1.363 + * followLinks 1.364 + * 1.365 + * This attribute will determine if the nsLocalFile will auto 1.366 + * resolve symbolic links. By default, this value will be false 1.367 + * on all non unix systems. On unix, this attribute is effectively 1.368 + * a noop. 1.369 + */ 1.370 + attribute boolean followLinks; 1.371 + 1.372 + /** 1.373 + * Flag for openNSPRFileDesc(), to hint to the OS that the file will be 1.374 + * read sequentially with agressive readahead. 1.375 + */ 1.376 + const unsigned long OS_READAHEAD = 0x40000000; 1.377 + 1.378 + /** 1.379 + * Flag for openNSPRFileDesc(). Deprecated and unreliable! 1.380 + * Instead use NS_OpenAnonymousTemporaryFile() to create a temporary 1.381 + * file which will be deleted upon close! 1.382 + */ 1.383 + const unsigned long DELETE_ON_CLOSE = 0x80000000; 1.384 + 1.385 + /** 1.386 + * Return the result of PR_Open on the file. The caller is 1.387 + * responsible for calling PR_Close on the result. 1.388 + * 1.389 + * @param flags the PR_Open flags from prio.h, plus optionally 1.390 + * OS_READAHEAD or DELETE_ON_CLOSE. OS_READAHEAD is a hint to the 1.391 + * OS that the file will be read sequentially with agressive 1.392 + * readahead. DELETE_ON_CLOSE is unreliable on Windows and is deprecated. 1.393 + * Instead use NS_OpenAnonymousTemporaryFile() to create a temporary 1.394 + * file which will be deleted upon close. 1.395 + */ 1.396 + [noscript] PRFileDescStar openNSPRFileDesc(in long flags, in long mode); 1.397 + 1.398 + /** 1.399 + * Return the result of fopen on the file. The caller is 1.400 + * responsible for calling fclose on the result. 1.401 + */ 1.402 + [noscript] FILE openANSIFileDesc(in string mode); 1.403 + 1.404 + /** 1.405 + * Return the result of PR_LoadLibrary on the file. The caller is 1.406 + * responsible for calling PR_UnloadLibrary on the result. 1.407 + */ 1.408 + [noscript] PRLibraryStar load(); 1.409 + 1.410 + // number of bytes available on disk to non-superuser 1.411 + readonly attribute int64_t diskSpaceAvailable; 1.412 + 1.413 + /** 1.414 + * appendRelative[Native]Path 1.415 + * 1.416 + * Append a relative path to the current path of the nsIFile object. 1.417 + * 1.418 + * @param relativeFilePath 1.419 + * relativeFilePath is a native relative path. For security reasons, 1.420 + * this cannot contain .. or cannot start with a directory separator. 1.421 + * For the |appendRelativeNativePath| method, the relativeFilePath 1.422 + * must be in the native filesystem charset. 1.423 + */ 1.424 + void appendRelativePath(in AString relativeFilePath); 1.425 + [noscript] void appendRelativeNativePath(in ACString relativeFilePath); 1.426 + 1.427 + /** 1.428 + * Accessor to a null terminated string which will specify 1.429 + * the file in a persistent manner for disk storage. 1.430 + * 1.431 + * The character set of this attribute is undefined. DO NOT TRY TO 1.432 + * INTERPRET IT AS HUMAN READABLE TEXT! 1.433 + */ 1.434 + attribute ACString persistentDescriptor; 1.435 + 1.436 + /** 1.437 + * reveal 1.438 + * 1.439 + * Ask the operating system to open the folder which contains 1.440 + * this file or folder. This routine only works on platforms which 1.441 + * support the ability to open a folder and is run async on Windows. 1.442 + * This routine must be called on the main. 1.443 + */ 1.444 + void reveal(); 1.445 + 1.446 + /** 1.447 + * launch 1.448 + * 1.449 + * Ask the operating system to attempt to open the file. 1.450 + * this really just simulates "double clicking" the file on your platform. 1.451 + * This routine only works on platforms which support this functionality 1.452 + * and is run async on Windows. This routine must be called on the 1.453 + * main thread. 1.454 + */ 1.455 + void launch(); 1.456 + 1.457 + /** 1.458 + * getRelativeDescriptor 1.459 + * 1.460 + * Returns a relative file path in an opaque, XP format. It is therefore 1.461 + * not a native path. 1.462 + * 1.463 + * The character set of the string returned from this function is 1.464 + * undefined. DO NOT TRY TO INTERPRET IT AS HUMAN READABLE TEXT! 1.465 + * 1.466 + * @param fromFile 1.467 + * the file from which the descriptor is relative. 1.468 + * There is no defined result if this param is null. 1.469 + */ 1.470 + ACString getRelativeDescriptor(in nsIFile fromFile); 1.471 + 1.472 + /** 1.473 + * setRelativeDescriptor 1.474 + * 1.475 + * Initializes the file to the location relative to fromFile using 1.476 + * a string returned by getRelativeDescriptor. 1.477 + * 1.478 + * @param fromFile 1.479 + * the file to which the descriptor is relative 1.480 + * @param relative 1.481 + * the relative descriptor obtained from getRelativeDescriptor 1.482 + */ 1.483 + void setRelativeDescriptor(in nsIFile fromFile, in ACString relativeDesc); 1.484 +}; 1.485 + 1.486 +%{C++ 1.487 +#ifdef MOZILLA_INTERNAL_API 1.488 +#include "nsDirectoryServiceUtils.h" 1.489 +#endif 1.490 +%}