OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 /** | 7 /** |
8 * The modes in which a File can be opened. | 8 * The modes in which a File can be opened. |
9 */ | 9 */ |
10 class FileMode { | 10 class FileMode { |
(...skipping 14 matching lines...) Expand all Loading... | |
25 /// The mode for opening a file only for reading. | 25 /// The mode for opening a file only for reading. |
26 const READ = FileMode.READ; | 26 const READ = FileMode.READ; |
27 /// The mode for opening a file for reading and writing. The file is | 27 /// The mode for opening a file for reading and writing. The file is |
28 /// overwritten if it already exists. The file is created if it does not | 28 /// overwritten if it already exists. The file is created if it does not |
29 /// already exist. | 29 /// already exist. |
30 const WRITE = FileMode.WRITE; | 30 const WRITE = FileMode.WRITE; |
31 /// The mode for opening a file for reading and writing to the | 31 /// The mode for opening a file for reading and writing to the |
32 /// end of it. The file is created if it does not already exist. | 32 /// end of it. The file is created if it does not already exist. |
33 const APPEND = FileMode.APPEND; | 33 const APPEND = FileMode.APPEND; |
34 | 34 |
35 /// Type of lock when requesting a lock on a file. | |
36 class FileLock { | |
Lasse Reichstein Nielsen
2015/01/08 11:59:22
Make this an enum.
Søren Gjesse
2015/01/09 13:06:20
Not yet. Enums still not enabled by default in dar
| |
37 final int _lock; | |
38 | |
39 /// Shared file lock. | |
40 static const SHARED = const FileLock._internal(0); | |
41 /// Exclusive file lock. | |
kustermann
2015/01/08 12:54:27
empty line before '///'.
Søren Gjesse
2015/01/09 13:06:20
Done.
| |
42 static const EXCLUSIVE = const FileLock._internal(1); | |
43 | |
44 const FileLock._internal(this._lock); | |
45 } | |
46 | |
35 /** | 47 /** |
36 * A reference to a file on the file system. | 48 * A reference to a file on the file system. |
37 * | 49 * |
38 * A File instance is an object that holds a [path] on which operations can | 50 * A File instance is an object that holds a [path] on which operations can |
39 * be performed. | 51 * be performed. |
40 * You can get the parent directory of the file using the getter [parent], | 52 * You can get the parent directory of the file using the getter [parent], |
41 * a property inherited from [FileSystemEntity]. | 53 * a property inherited from [FileSystemEntity]. |
42 * | 54 * |
43 * Create a new File object with a pathname to access the specified file on the | 55 * Create a new File object with a pathname to access the specified file on the |
44 * file system from your program. | 56 * file system from your program. |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
691 Future<RandomAccessFile> flush(); | 703 Future<RandomAccessFile> flush(); |
692 | 704 |
693 /** | 705 /** |
694 * Synchronously flushes the contents of the file to disk. | 706 * Synchronously flushes the contents of the file to disk. |
695 * | 707 * |
696 * Throws a [FileSystemException] if the operation fails. | 708 * Throws a [FileSystemException] if the operation fails. |
697 */ | 709 */ |
698 void flushSync(); | 710 void flushSync(); |
699 | 711 |
700 /** | 712 /** |
713 * Locks the file or part of the file. | |
714 * | |
715 * Locks the byte range from [start] to [end] of the file, with the | |
716 * byte at position `end` not included. If no arguments are | |
717 * specified, the full file is locked, If only `start` is specified | |
718 * the file is locked from byte position `start` to the end of the | |
719 * file. | |
720 * | |
721 * By default an exclusive lock will be obtained, but that can be overridden | |
722 * by the [mode] argument. | |
723 * | |
724 * To obtain an exclusive lock on a file it must be opened for writing. | |
725 * | |
726 * *NOTE* file locking does have slight differences in behavior across | |
727 * platforms: | |
728 * | |
729 * On Linux and Mac OS this uses advisory locks, which have the surprising | |
730 * semantics that all locks associated with a given file are removed when | |
731 * *any* file descriptor for that file is closed by the process. | |
Lasse Reichstein Nielsen
2015/01/08 11:59:22
Worth mentioning that advisory locks are not actua
Søren Gjesse
2015/01/09 13:06:20
Done.
| |
732 * | |
733 * On Windows the regions used for lock and unlock needs to match. If that | |
734 * is not the case unlocking will result in the OS error "The segment is | |
735 * already unlocked". | |
736 */ | |
737 Future<RandomAccessFile> lock( | |
738 [int start, int end, FileLock mode = FileLock.EXCLUSIVE]); | |
Lasse Reichstein Nielsen
2015/01/08 11:59:22
As discussed, move mode to first argument.
Maybe o
Søren Gjesse
2015/01/09 13:06:20
Done.
| |
739 | |
740 /** | |
741 * Synchronously locks the file or part of the file. | |
742 * | |
743 * Locks the byte range from [start] to [end] of the file ,with the | |
744 * byte at position `end` not included. If no arguments are | |
745 * specified, the full file is locked, If only `start` is specified | |
746 * the file is locked from byte position `start` to the end of the | |
747 * file. | |
748 * | |
749 * By default an exclusive lock will be obtained, but that can be overridden | |
750 * by the [mode] argument. | |
751 * | |
752 * To obtain an exclusive lock on a file it must be opened for writing. | |
753 * | |
754 * *NOTE* file locking does have slight differences in behavior across | |
755 * platforms: | |
756 * | |
757 * On Linux and Mac OS this uses advisory locks, which have the surprising | |
758 * semantics that all locks associated with a given file are removed when | |
759 * *any* file descriptor for that file is closed by the process. | |
760 * | |
761 * On Windows the regions used for lock and unlock needs to match. If that | |
762 * is not the case unlocking will result in the OS error "The segment is | |
763 * already unlocked". | |
764 */ | |
765 void lockSync([int start, int end, FileLock mode = FileLock.EXCLUSIVE]); | |
766 | |
767 /** | |
768 * Unlocks the file or part of the file. | |
769 * | |
770 * Unlocks the byte range from [start] to [end] of the file, with | |
771 * the byte at position `end` not included. If no arguments are | |
772 * specified, the full file is unlocked, If only `start` is | |
773 * specified the file is unlocked from byte position `start` to the | |
774 * end of the file. | |
775 * | |
776 * *NOTE* file locking does have slight differences in behavior across | |
777 * platforms: | |
778 * | |
779 * See [lock] for more details. | |
780 */ | |
781 Future<RandomAccessFile> unlock([int start, int end]); | |
Lasse Reichstein Nielsen
2015/01/08 11:59:22
Maybe default start to 0.
kustermann
2015/01/08 12:54:27
Why is lockSync(), unlockSync() returning void and
Søren Gjesse
2015/01/09 13:06:20
This is the convention for RandomAccessFile. All a
Søren Gjesse
2015/01/09 13:06:20
Done.
| |
782 | |
783 /** | |
784 * Synchronously unlocks the file or part of the file. | |
785 * | |
786 * Unlocks the byte range from [start] to [end] of the file, with | |
787 * the byte at position `end` not included. If no arguments are | |
788 * specified, the full file is unlocked, If only `start` is | |
789 * specified the file is unlocked from byte position `start` to the | |
790 * end of the file. | |
791 * | |
792 * *NOTE* file locking does have slight differences in behavior across | |
793 * platforms: | |
794 * | |
795 * See [lockSync] for more details. | |
796 */ | |
797 void unlockSync([int start, int end]); | |
798 | |
799 /** | |
701 * Returns a human-readable string for this RandomAccessFile instance. | 800 * Returns a human-readable string for this RandomAccessFile instance. |
702 */ | 801 */ |
703 String toString(); | 802 String toString(); |
704 | 803 |
705 /** | 804 /** |
706 * Gets the path of the file underlying this RandomAccessFile. | 805 * Gets the path of the file underlying this RandomAccessFile. |
707 */ | 806 */ |
708 String get path; | 807 String get path; |
709 } | 808 } |
710 | 809 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
754 sb.write(": $osError"); | 853 sb.write(": $osError"); |
755 if (path != null) { | 854 if (path != null) { |
756 sb.write(", path = '$path'"); | 855 sb.write(", path = '$path'"); |
757 } | 856 } |
758 } else if (path != null) { | 857 } else if (path != null) { |
759 sb.write(": $path"); | 858 sb.write(": $path"); |
760 } | 859 } |
761 return sb.toString(); | 860 return sb.toString(); |
762 } | 861 } |
763 } | 862 } |
OLD | NEW |