Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: sdk/lib/io/file.dart

Issue 2050413002: Adds blocking file locks. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update docs and CHANGELOG Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/file_win.cc ('k') | sdk/lib/io/file_impl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 /// Mode for opening a file for writing *only* to the 45 /// Mode for opening a file for writing *only* to the
46 /// end of it. The file is created if it does not already exist. 46 /// end of it. The file is created if it does not already exist.
47 const WRITE_ONLY_APPEND = FileMode.WRITE_ONLY_APPEND; 47 const WRITE_ONLY_APPEND = FileMode.WRITE_ONLY_APPEND;
48 48
49 49
50 /// Type of lock when requesting a lock on a file. 50 /// Type of lock when requesting a lock on a file.
51 enum FileLock { 51 enum FileLock {
52 /// Shared file lock. 52 /// Shared file lock.
53 SHARED, 53 SHARED,
54 /// Exclusive file lock. 54 /// Exclusive file lock.
55 EXCLUSIVE 55 EXCLUSIVE,
56 /// Blocking shared file lock.
57 BLOCKING_SHARED,
58 /// Blocking exclusive file lock.
59 BLOCKING_EXCLUSIVE,
56 } 60 }
57 61
58 /** 62 /**
59 * A reference to a file on the file system. 63 * A reference to a file on the file system.
60 * 64 *
61 * A File instance is an object that holds a [path] on which operations can 65 * A File instance is an object that holds a [path] on which operations can
62 * be performed. 66 * be performed.
63 * You can get the parent directory of the file using the getter [parent], 67 * You can get the parent directory of the file using the getter [parent],
64 * a property inherited from [FileSystemEntity]. 68 * a property inherited from [FileSystemEntity].
65 * 69 *
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 * 732 *
729 * Locks the byte range from [start] to [end] of the file, with the 733 * Locks the byte range from [start] to [end] of the file, with the
730 * byte at position `end` not included. If no arguments are 734 * byte at position `end` not included. If no arguments are
731 * specified, the full file is locked, If only `start` is specified 735 * specified, the full file is locked, If only `start` is specified
732 * the file is locked from byte position `start` to the end of the 736 * the file is locked from byte position `start` to the end of the
733 * file, no matter how large it grows. It is possible to specify an 737 * file, no matter how large it grows. It is possible to specify an
734 * explicit value of `end` which is past the current length of the file. 738 * explicit value of `end` which is past the current length of the file.
735 * 739 *
736 * To obtain an exclusive lock on a file it must be opened for writing. 740 * To obtain an exclusive lock on a file it must be opened for writing.
737 * 741 *
742 * If [mode] is [FileLock.EXCLUSIVE] or [FileLock.SHARED], an error is
743 * signaled if the lock cannot be obtained. If [mode] is
744 * [FileLock.BLOCKING_EXCLUSIVE] or [FileLock.BLOCKING_SHARED], the
745 * returned [Future] is resolved only when the lock has been obtained.
746 *
siva 2016/06/13 15:56:08 This operation is not synchronous, should we allow
zra 2016/06/13 16:03:33 This call is implemented as a request sent to the
Søren Gjesse 2016/06/13 16:05:09 The blocking I/O call is dispatched on the "native
738 * *NOTE* file locking does have slight differences in behavior across 747 * *NOTE* file locking does have slight differences in behavior across
739 * platforms: 748 * platforms:
740 * 749 *
741 * On Linux and OS X this uses advisory locks, which have the 750 * On Linux and OS X this uses advisory locks, which have the
742 * surprising semantics that all locks associated with a given file 751 * surprising semantics that all locks associated with a given file
743 * are removed when *any* file descriptor for that file is closed by 752 * are removed when *any* file descriptor for that file is closed by
744 * the process. Note that this does not actually lock the file for 753 * the process. Note that this does not actually lock the file for
745 * access. Also note that advisory locks are on a process 754 * access. Also note that advisory locks are on a process
746 * level. This means that several isolates in the same process can 755 * level. This means that several isolates in the same process can
747 * obtain an exclusive lock on the same file. 756 * obtain an exclusive lock on the same file.
(...skipping 13 matching lines...) Expand all
761 * 770 *
762 * Locks the byte range from [start] to [end] of the file ,with the 771 * Locks the byte range from [start] to [end] of the file ,with the
763 * byte at position `end` not included. If no arguments are 772 * byte at position `end` not included. If no arguments are
764 * specified, the full file is locked, If only `start` is specified 773 * specified, the full file is locked, If only `start` is specified
765 * the file is locked from byte position `start` to the end of the 774 * the file is locked from byte position `start` to the end of the
766 * file, no matter how large it grows. It is possible to specify an 775 * file, no matter how large it grows. It is possible to specify an
767 * explicit value of `end` which is past the current length of the file. 776 * explicit value of `end` which is past the current length of the file.
768 * 777 *
769 * To obtain an exclusive lock on a file it must be opened for writing. 778 * To obtain an exclusive lock on a file it must be opened for writing.
770 * 779 *
780 * If [mode] is [FileLock.EXCLUSIVE] or [FileLock.SHARED], an exception is
781 * thrown if the lock cannot be obtained. If [mode] is
782 * [FileLock.BLOCKING_EXCLUSIVE] or [FileLock.BLOCKING_SHARED], the
783 * call returns only after the lock has been obtained.
784 *
771 * *NOTE* file locking does have slight differences in behavior across 785 * *NOTE* file locking does have slight differences in behavior across
772 * platforms: 786 * platforms:
773 * 787 *
774 * On Linux and OS X this uses advisory locks, which have the 788 * On Linux and OS X this uses advisory locks, which have the
775 * surprising semantics that all locks associated with a given file 789 * surprising semantics that all locks associated with a given file
776 * are removed when *any* file descriptor for that file is closed by 790 * are removed when *any* file descriptor for that file is closed by
777 * the process. Note that this does not actually lock the file for 791 * the process. Note that this does not actually lock the file for
778 * access. Also note that advisory locks are on a process 792 * access. Also note that advisory locks are on a process
779 * level. This means that several isolates in the same process can 793 * level. This means that several isolates in the same process can
780 * obtain an exclusive lock on the same file. 794 * obtain an exclusive lock on the same file.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 sb.write(": $osError"); 890 sb.write(": $osError");
877 if (path != null) { 891 if (path != null) {
878 sb.write(", path = '$path'"); 892 sb.write(", path = '$path'");
879 } 893 }
880 } else if (path != null) { 894 } else if (path != null) {
881 sb.write(": $path"); 895 sb.write(": $path");
882 } 896 }
883 return sb.toString(); 897 return sb.toString();
884 } 898 }
885 } 899 }
OLDNEW
« no previous file with comments | « runtime/bin/file_win.cc ('k') | sdk/lib/io/file_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698