@@ -4,12 +4,15 @@ import 'dart:io';
44import 'package:flutter/foundation.dart' ;
55import 'package:lw_file_system/lw_file_system.dart' ;
66import 'package:path/path.dart' as p;
7+ import 'package:synchronized/synchronized.dart' ;
78
89class IODirectoryFileSystem extends DirectoryFileSystem {
910 @override
1011 final LocalStorage ? storage;
1112 final bool useIsolates;
1213
14+ final _lock = Lock ();
15+
1316 IODirectoryFileSystem ({
1417 this .storage,
1518 required super .config,
@@ -62,21 +65,25 @@ class IODirectoryFileSystem extends DirectoryFileSystem {
6265 @override
6366 Future <RawFileSystemDirectory > createDirectory (String path) async {
6467 path = normalizePath (path);
65- final directory = Directory (await getAbsolutePath (path));
66- if (! await directory.exists ()) {
67- await directory.create (recursive: true );
68- }
69- return RawFileSystemDirectory (
70- AssetLocation (path: path, remote: remoteName),
71- assets: [],
72- );
68+ return _lock.synchronized (() async {
69+ final directory = Directory (await getAbsolutePath (path));
70+ if (! await directory.exists ()) {
71+ await directory.create (recursive: true );
72+ }
73+ return RawFileSystemDirectory (
74+ AssetLocation (path: path, remote: remoteName),
75+ assets: [],
76+ );
77+ });
7378 }
7479
7580 @override
7681 Future <void > deleteAsset (String path) async {
7782 path = normalizePath (path);
78- // This removes all types of entities
79- await Directory (await getAbsolutePath (path)).delete (recursive: true );
83+ return _lock.synchronized (() async {
84+ // This removes all types of entities
85+ await Directory (await getAbsolutePath (path)).delete (recursive: true );
86+ });
8087 }
8188
8289 @override
@@ -87,11 +94,13 @@ class IODirectoryFileSystem extends DirectoryFileSystem {
8794 }) async {
8895 path = normalizePath (path);
8996 path = await getAbsolutePath (path);
90- if (useIsolates) {
91- await compute (_updateFile, (path, data));
92- } else {
93- await _updateFile ((path, data));
94- }
97+ return _lock.synchronized (() async {
98+ if (useIsolates) {
99+ await compute (_updateFile, (path, data));
100+ } else {
101+ await _updateFile ((path, data));
102+ }
103+ });
95104 }
96105
97106 Future <void > _updateFile ((String , Uint8List ) e) async {
0 commit comments