Skip to content

Commit 135e10a

Browse files
greglittlefield-wfjonasfj
authored andcommitted
Update last modified date directly in touch (#2014)
This mitigates race conditions in which concurrent Pub processes "touch" pubspec.lock around the same time and leave it with a trailing NUL character.
1 parent 980fc94 commit 135e10a

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

lib/src/io.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -799,13 +799,7 @@ _doProcess(Function fn, String executable, List<String> args,
799799
}
800800

801801
/// Updates [path]'s modification time.
802-
void touch(String path) {
803-
var file = File(path).openSync(mode: FileMode.append);
804-
var originalLength = file.lengthSync();
805-
file.writeByteSync(0);
806-
file.truncateSync(originalLength);
807-
file.closeSync();
808-
}
802+
void touch(String path) => File(path).setLastModifiedSync(DateTime.now());
809803

810804
/// Creates a temporary directory and passes its path to [fn].
811805
///

0 commit comments

Comments
 (0)