Bumping manifests a=b2g-bump
[gecko.git] / xpcom / io / nsIFile.idl
blob2372dde1d626145a0ef4d471730be18ce0c59287
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsISupports.idl"
8 %{C++
9 struct PRFileDesc;
10 struct PRLibrary;
11 #include <stdio.h>
14 [ptr] native PRFileDescStar(PRFileDesc);
15 [ptr] native PRLibraryStar(PRLibrary);
16 [ptr] native FILE(FILE);
18 interface nsISimpleEnumerator;
20 /**
21 * An nsIFile is an abstract representation of a filename. It manages
22 * filename encoding issues, pathname component separators ('/' vs. '\\'
23 * vs. ':') and weird stuff like differing volumes with identical names, as
24 * on pre-Darwin Macintoshes.
26 * This file has long introduced itself to new hackers with this opening
27 * paragraph:
29 * This is the only correct cross-platform way to specify a file.
30 * Strings are not such a way. If you grew up on windows or unix, you
31 * may think they are. Welcome to reality.
33 * While taking the pose struck here to heart would be uncalled for, one
34 * may safely conclude that writing cross-platform code is an embittering
35 * experience.
37 * All methods with string parameters have two forms. The preferred
38 * form operates on UCS-2 encoded characters strings. An alternate
39 * form operates on characters strings encoded in the "native" charset.
41 * A string containing characters encoded in the native charset cannot
42 * be safely passed to javascript via xpconnect. Therefore, the "native
43 * methods" are not scriptable.
45 [scriptable, uuid(dfb5a307-7ecf-41dd-aee2-f1d623459c44), builtinclass]
46 interface nsIFile : nsISupports
48 /**
49 * Create Types
51 * NORMAL_FILE_TYPE - A normal file.
52 * DIRECTORY_TYPE - A directory/folder.
54 const unsigned long NORMAL_FILE_TYPE = 0;
55 const unsigned long DIRECTORY_TYPE = 1;
57 /**
58 * append[Native]
60 * This function is used for constructing a descendent of the
61 * current nsIFile.
63 * @param node
64 * A string which is intended to be a child node of the nsIFile.
65 * For the |appendNative| method, the node must be in the native
66 * filesystem charset.
68 void append(in AString node);
69 [noscript] void appendNative(in ACString node);
71 /**
72 * Normalize the pathName (e.g. removing .. and . components on Unix).
74 void normalize();
76 /**
77 * create
79 * This function will create a new file or directory in the
80 * file system. Any nodes that have not been created or
81 * resolved, will be. If the file or directory already
82 * exists create() will return NS_ERROR_FILE_ALREADY_EXISTS.
84 * @param type
85 * This specifies the type of file system object
86 * to be made. The only two types at this time
87 * are file and directory which are defined above.
88 * If the type is unrecongnized, we will return an
89 * error (NS_ERROR_FILE_UNKNOWN_TYPE).
91 * @param permissions
92 * The unix style octal permissions. This may
93 * be ignored on systems that do not need to do
94 * permissions.
96 void create(in unsigned long type, in unsigned long permissions);
98 /**
99 * Accessor to the leaf name of the file itself.
100 * For the |nativeLeafName| method, the nativeLeafName must
101 * be in the native filesystem charset.
103 attribute AString leafName;
104 [noscript] attribute ACString nativeLeafName;
107 * copyTo[Native]
109 * This will copy this file to the specified newParentDir.
110 * If a newName is specified, the file will be renamed.
111 * If 'this' is not created we will return an error
112 * (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST).
114 * copyTo may fail if the file already exists in the destination
115 * directory.
117 * copyTo will NOT resolve aliases/shortcuts during the copy.
119 * @param newParentDir
120 * This param is the destination directory. If the
121 * newParentDir is null, copyTo() will use the parent
122 * directory of this file. If the newParentDir is not
123 * empty and is not a directory, an error will be
124 * returned (NS_ERROR_FILE_DESTINATION_NOT_DIR). For the
125 * |CopyToNative| method, the newName must be in the
126 * native filesystem charset.
128 * @param newName
129 * This param allows you to specify a new name for
130 * the file to be copied. This param may be empty, in
131 * which case the current leaf name will be used.
133 void copyTo(in nsIFile newParentDir, in AString newName);
134 [noscript] void CopyToNative(in nsIFile newParentDir, in ACString newName);
137 * copyToFollowingLinks[Native]
139 * This function is identical to copyTo with the exception that,
140 * as the name implies, it follows symbolic links. The XP_UNIX
141 * implementation always follow symbolic links when copying. For
142 * the |CopyToFollowingLinks| method, the newName must be in the
143 * native filesystem charset.
145 void copyToFollowingLinks(in nsIFile newParentDir, in AString newName);
146 [noscript] void copyToFollowingLinksNative(in nsIFile newParentDir, in ACString newName);
149 * moveTo[Native]
151 * A method to move this file or directory to newParentDir.
152 * If a newName is specified, the file or directory will be renamed.
153 * If 'this' is not created we will return an error
154 * (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST).
155 * If 'this' is a file, and the destination file already exists, moveTo
156 * will replace the old file.
157 * This object is updated to refer to the new file.
159 * moveTo will NOT resolve aliases/shortcuts during the copy.
160 * moveTo will do the right thing and allow copies across volumes.
161 * moveTo will return an error (NS_ERROR_FILE_DIR_NOT_EMPTY) if 'this' is
162 * a directory and the destination directory is not empty.
163 * moveTo will return an error (NS_ERROR_FILE_ACCESS_DENIED) if 'this' is
164 * a directory and the destination directory is not writable.
166 * @param newParentDir
167 * This param is the destination directory. If the
168 * newParentDir is empty, moveTo() will rename the file
169 * within its current directory. If the newParentDir is
170 * not empty and does not name a directory, an error will
171 * be returned (NS_ERROR_FILE_DESTINATION_NOT_DIR). For
172 * the |moveToNative| method, the newName must be in the
173 * native filesystem charset.
175 * @param newName
176 * This param allows you to specify a new name for
177 * the file to be moved. This param may be empty, in
178 * which case the current leaf name will be used.
180 void moveTo(in nsIFile newParentDir, in AString newName);
181 [noscript] void moveToNative(in nsIFile newParentDir, in ACString newName);
184 * renameTo
186 * This method is identical to moveTo except that if this file or directory
187 * is moved to a a different volume, it fails and returns an error
188 * (NS_ERROR_FILE_ACCESS_DENIED).
189 * This object will still point to the old location after renaming.
191 void renameTo(in nsIFile newParentDir, in AString newName);
194 * This will try to delete this file. The 'recursive' flag
195 * must be PR_TRUE to delete directories which are not empty.
197 * This will not resolve any symlinks.
199 void remove(in boolean recursive);
202 * Attributes of nsIFile.
205 attribute unsigned long permissions;
206 attribute unsigned long permissionsOfLink;
209 * File Times are to be in milliseconds from
210 * midnight (00:00:00), January 1, 1970 Greenwich Mean
211 * Time (GMT).
213 attribute PRTime lastModifiedTime;
214 attribute PRTime lastModifiedTimeOfLink;
217 * WARNING! On the Mac, getting/setting the file size with nsIFile
218 * only deals with the size of the data fork. If you need to
219 * know the size of the combined data and resource forks use the
220 * GetFileSizeWithResFork() method defined on nsILocalFileMac.
222 attribute int64_t fileSize;
223 readonly attribute int64_t fileSizeOfLink;
226 * target & path
228 * Accessor to the string path. The native version of these
229 * strings are not guaranteed to be a usable path to pass to
230 * NSPR or the C stdlib. There are problems that affect
231 * platforms on which a path does not fully specify a file
232 * because two volumes can have the same name (e.g., mac).
233 * This is solved by holding "private", native data in the
234 * nsIFile implementation. This native data is lost when
235 * you convert to a string.
237 * DO NOT PASS TO USE WITH NSPR OR STDLIB!
239 * target
240 * Find out what the symlink points at. Will give error
241 * (NS_ERROR_FILE_INVALID_PATH) if not a symlink.
243 * path
244 * Find out what the nsIFile points at.
246 * Note that the ACString attributes are returned in the
247 * native filesystem charset.
250 readonly attribute AString target;
251 [noscript] readonly attribute ACString nativeTarget;
252 readonly attribute AString path;
253 [noscript] readonly attribute ACString nativePath;
255 boolean exists();
256 boolean isWritable();
257 boolean isReadable();
258 boolean isExecutable();
259 boolean isHidden();
260 boolean isDirectory();
261 boolean isFile();
262 boolean isSymlink();
264 * Not a regular file, not a directory, not a symlink.
266 boolean isSpecial();
269 * createUnique
271 * This function will create a new file or directory in the
272 * file system. Any nodes that have not been created or
273 * resolved, will be. If this file already exists, we try
274 * variations on the leaf name "suggestedName" until we find
275 * one that did not already exist.
277 * If the search for nonexistent files takes too long
278 * (thousands of the variants already exist), we give up and
279 * return NS_ERROR_FILE_TOO_BIG.
281 * @param type
282 * This specifies the type of file system object
283 * to be made. The only two types at this time
284 * are file and directory which are defined above.
285 * If the type is unrecongnized, we will return an
286 * error (NS_ERROR_FILE_UNKNOWN_TYPE).
288 * @param permissions
289 * The unix style octal permissions. This may
290 * be ignored on systems that do not need to do
291 * permissions.
293 void createUnique(in unsigned long type, in unsigned long permissions);
296 * clone()
298 * This function will allocate and initialize a nsIFile object to the
299 * exact location of the |this| nsIFile.
301 * @param file
302 * A nsIFile which this object will be initialize
303 * with.
306 nsIFile clone();
309 * Will determine if the inFile equals this.
311 boolean equals(in nsIFile inFile);
314 * Will determine if inFile is a descendant of this file.
315 * This routine looks in subdirectories too.
317 boolean contains(in nsIFile inFile);
320 * Parent will be null when this is at the top of the volume.
322 readonly attribute nsIFile parent;
325 * Returns an enumeration of the elements in a directory. Each
326 * element in the enumeration is an nsIFile.
328 * @throws NS_ERROR_FILE_NOT_DIRECTORY if the current nsIFile does
329 * not specify a directory.
331 readonly attribute nsISimpleEnumerator directoryEntries;
334 * initWith[Native]Path
336 * This function will initialize the nsIFile object. Any
337 * internal state information will be reset.
339 * @param filePath
340 * A string which specifies a full file path to a
341 * location. Relative paths will be treated as an
342 * error (NS_ERROR_FILE_UNRECOGNIZED_PATH). For
343 * initWithNativePath, the filePath must be in the native
344 * filesystem charset.
346 void initWithPath(in AString filePath);
347 [noscript] void initWithNativePath(in ACString filePath);
350 * initWithFile
352 * Initialize this object with another file
354 * @param aFile
355 * the file this becomes equivalent to
357 void initWithFile(in nsIFile aFile);
360 * followLinks
362 * This attribute will determine if the nsLocalFile will auto
363 * resolve symbolic links. By default, this value will be false
364 * on all non unix systems. On unix, this attribute is effectively
365 * a noop.
367 attribute boolean followLinks;
370 * Flag for openNSPRFileDesc(), to hint to the OS that the file will be
371 * read sequentially with agressive readahead.
373 const unsigned long OS_READAHEAD = 0x40000000;
376 * Flag for openNSPRFileDesc(). Deprecated and unreliable!
377 * Instead use NS_OpenAnonymousTemporaryFile() to create a temporary
378 * file which will be deleted upon close!
380 const unsigned long DELETE_ON_CLOSE = 0x80000000;
383 * Return the result of PR_Open on the file. The caller is
384 * responsible for calling PR_Close on the result.
386 * @param flags the PR_Open flags from prio.h, plus optionally
387 * OS_READAHEAD or DELETE_ON_CLOSE. OS_READAHEAD is a hint to the
388 * OS that the file will be read sequentially with agressive
389 * readahead. DELETE_ON_CLOSE is unreliable on Windows and is deprecated.
390 * Instead use NS_OpenAnonymousTemporaryFile() to create a temporary
391 * file which will be deleted upon close.
393 [noscript] PRFileDescStar openNSPRFileDesc(in long flags, in long mode);
396 * Return the result of fopen on the file. The caller is
397 * responsible for calling fclose on the result.
399 [noscript] FILE openANSIFileDesc(in string mode);
402 * Return the result of PR_LoadLibrary on the file. The caller is
403 * responsible for calling PR_UnloadLibrary on the result.
405 [noscript] PRLibraryStar load();
407 // number of bytes available on disk to non-superuser
408 readonly attribute int64_t diskSpaceAvailable;
411 * appendRelative[Native]Path
413 * Append a relative path to the current path of the nsIFile object.
415 * @param relativeFilePath
416 * relativeFilePath is a native relative path. For security reasons,
417 * this cannot contain .. or cannot start with a directory separator.
418 * For the |appendRelativeNativePath| method, the relativeFilePath
419 * must be in the native filesystem charset.
421 void appendRelativePath(in AString relativeFilePath);
422 [noscript] void appendRelativeNativePath(in ACString relativeFilePath);
425 * Accessor to a null terminated string which will specify
426 * the file in a persistent manner for disk storage.
428 * The character set of this attribute is undefined. DO NOT TRY TO
429 * INTERPRET IT AS HUMAN READABLE TEXT!
431 attribute ACString persistentDescriptor;
433 /**
434 * reveal
436 * Ask the operating system to open the folder which contains
437 * this file or folder. This routine only works on platforms which
438 * support the ability to open a folder and is run async on Windows.
439 * This routine must be called on the main.
441 void reveal();
443 /**
444 * launch
446 * Ask the operating system to attempt to open the file.
447 * this really just simulates "double clicking" the file on your platform.
448 * This routine only works on platforms which support this functionality
449 * and is run async on Windows. This routine must be called on the
450 * main thread.
452 void launch();
455 * getRelativeDescriptor
457 * Returns a relative file path in an opaque, XP format. It is therefore
458 * not a native path.
460 * The character set of the string returned from this function is
461 * undefined. DO NOT TRY TO INTERPRET IT AS HUMAN READABLE TEXT!
463 * @param fromFile
464 * the file from which the descriptor is relative.
465 * There is no defined result if this param is null.
467 ACString getRelativeDescriptor(in nsIFile fromFile);
470 * setRelativeDescriptor
472 * Initializes the file to the location relative to fromFile using
473 * a string returned by getRelativeDescriptor.
475 * @param fromFile
476 * the file to which the descriptor is relative
477 * @param relative
478 * the relative descriptor obtained from getRelativeDescriptor
480 void setRelativeDescriptor(in nsIFile fromFile, in ACString relativeDesc);
483 %{C++
484 #ifdef MOZILLA_INTERNAL_API
485 #include "nsDirectoryServiceUtils.h"
486 #endif