@@ -13,85 +13,71 @@ public actor FileManagerStorageAdapter: LocalStorageAdapter {
1313 }
1414
1515 public func saveFile( filePath: String , data: Data ) async throws -> Int64 {
16- return try await Task {
17- let url = URL ( fileURLWithPath: filePath)
16+ let url = URL ( fileURLWithPath: filePath)
1817
19- // Make sure the parent directory exists
20- try fileManager. createDirectory ( at: url. deletingLastPathComponent ( ) ,
21- withIntermediateDirectories: true )
18+ // Make sure the parent directory exists
19+ try fileManager. createDirectory ( at: url. deletingLastPathComponent ( ) ,
20+ withIntermediateDirectories: true )
2221
23- // Write data to file
24- try data. write ( to: url)
22+ // Write data to file
23+ try data. write ( to: url)
2524
26- // Return the size of the data
27- return Int64 ( data. count)
28- } . value
25+ // Return the size of the data
26+ return Int64 ( data. count)
2927 }
3028
3129 public func readFile( filePath: String , mediaType _: String ? ) async throws -> Data {
32- return try await Task {
33- let url = URL ( fileURLWithPath: filePath)
34-
35- if !fileManager. fileExists ( atPath: filePath) {
36- throw PowerSyncAttachmentError . fileNotFound ( filePath)
37- }
38-
39- // Read data from file
40- do {
41- return try Data ( contentsOf: url)
42- } catch {
43- throw PowerSyncAttachmentError . ioError ( error)
44- }
45- } . value
30+ let url = URL ( fileURLWithPath: filePath)
31+
32+ if !fileManager. fileExists ( atPath: filePath) {
33+ throw PowerSyncAttachmentError . fileNotFound ( filePath)
34+ }
35+
36+ // Read data from file
37+ do {
38+ return try Data ( contentsOf: url)
39+ } catch {
40+ throw PowerSyncAttachmentError . ioError ( error)
41+ }
4642 }
4743
4844 public func deleteFile( filePath: String ) async throws {
49- try await Task {
50- if fileManager. fileExists ( atPath: filePath) {
51- try fileManager. removeItem ( atPath: filePath)
52- }
53- } . value
45+ if fileManager. fileExists ( atPath: filePath) {
46+ try fileManager. removeItem ( atPath: filePath)
47+ }
5448 }
5549
5650 public func fileExists( filePath: String ) async throws -> Bool {
57- return await Task {
58- fileManager. fileExists ( atPath: filePath)
59- } . value
51+ return fileManager. fileExists ( atPath: filePath)
6052 }
6153
6254 public func makeDir( path: String ) async throws {
63- try await Task {
64- try fileManager. createDirectory ( atPath: path,
65- withIntermediateDirectories: true ,
66- attributes: nil )
67- } . value
55+ try fileManager. createDirectory ( atPath: path,
56+ withIntermediateDirectories: true ,
57+ attributes: nil )
6858 }
6959
7060 public func rmDir( path: String ) async throws {
71- try await Task {
72- if fileManager. fileExists ( atPath: path) {
73- try fileManager. removeItem ( atPath: path)
74- }
75- } . value
61+ if fileManager. fileExists ( atPath: path) {
62+ try fileManager. removeItem ( atPath: path)
63+ }
7664 }
7765
7866 public func copyFile( sourcePath: String , targetPath: String ) async throws {
79- try await Task {
80- if !fileManager. fileExists ( atPath: sourcePath) {
81- throw PowerSyncAttachmentError . fileNotFound ( sourcePath)
82- }
83-
84- // Ensure target directory exists
85- let targetUrl = URL ( fileURLWithPath: targetPath)
86- try fileManager. createDirectory ( at: targetUrl. deletingLastPathComponent ( ) ,
87- withIntermediateDirectories: true )
88-
89- // If target already exists, remove it first
90- if fileManager. fileExists ( atPath: targetPath) {
91- try fileManager. removeItem ( atPath: targetPath)
92- }
93-
94- try fileManager. copyItem ( atPath: sourcePath, toPath: targetPath)
95- } . value
67+ if !fileManager. fileExists ( atPath: sourcePath) {
68+ throw PowerSyncAttachmentError . fileNotFound ( sourcePath)
69+ }
70+
71+ // Ensure target directory exists
72+ let targetUrl = URL ( fileURLWithPath: targetPath)
73+ try fileManager. createDirectory ( at: targetUrl. deletingLastPathComponent ( ) ,
74+ withIntermediateDirectories: true )
75+
76+ // If target already exists, remove it first
77+ if fileManager. fileExists ( atPath: targetPath) {
78+ try fileManager. removeItem ( atPath: targetPath)
79+ }
80+
81+ try fileManager. copyItem ( atPath: sourcePath, toPath: targetPath)
9682 }
9783}
0 commit comments