Skip to content

Commit cb3d696

Browse files
committed
Chore: Code style tweaks
1 parent 33620c2 commit cb3d696

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

lib/data/file_manager/file_manager.dart

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,18 @@ class FileManager {
176176
static Directory getRootDirectory() => Directory(documentsDirectory);
177177

178178
/// Writes [toWrite] to [filePath].
179-
static Future<void> writeFile(String filePath, List<int> toWrite,
180-
{bool awaitWrite = false, bool alsoUpload = true, DateTime? lastModified}) async {
181-
// if lastModified is used, then last modified time stamp is set after file write
182-
// it is used when downloading remote file, to set the same time stamp as has the file
179+
///
180+
/// The file at [toPath] will have its last modified timestamp set to
181+
/// [lastModified], if specified.
182+
/// This is useful when downloading remote files, to make sure that the
183+
/// timestamp is the same locally and remotely.
184+
static Future<void> writeFile(
185+
String filePath,
186+
List<int> toWrite, {
187+
bool awaitWrite = false,
188+
bool alsoUpload = true,
189+
DateTime? lastModified,
190+
}) async {
183191
filePath = _sanitisePath(filePath);
184192
log.fine('Writing to $filePath');
185193

@@ -201,9 +209,7 @@ class FileManager {
201209
]);
202210

203211
void afterWrite() {
204-
if (lastModified != null){
205-
// want to set timestamp of last modification. Used when downloading remote file, to put the same time stamp
206-
// to avoid synchronization of newly created file back to remote.
212+
if (lastModified != null) {
207213
file.setLastModified(lastModified);
208214
}
209215
broadcastFileWrite(FileOperationType.write, filePath);

lib/data/nextcloud/saber_syncer.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,10 @@ class SaberSyncInterface
129129

130130
@override
131131
Future<SaberSyncFile> getSyncFileFromLocalFile(File localFile) async {
132-
String relativePath =
133-
localFile.path.substring(FileManager.documentsDirectory.length);
134-
String separator=Platform.pathSeparator;
135-
if (separator != "/") {
136-
// I am on windows - replace \ with /
137-
relativePath=relativePath.replaceAll("\\","/");
138-
}
132+
final relativePath = localFile.path
133+
.substring(FileManager.documentsDirectory.length)
134+
// Compensate for Windows using backslashes
135+
.replaceAll(Platform.pathSeparator, '/');
139136

140137
assert(relativePath.startsWith('/'));
141138
final encryptedName = await encryptPath(client, relativePath);
@@ -229,8 +226,13 @@ class SaberSyncInterface
229226
);
230227
assert(decryptedData.isNotEmpty,
231228
'Decrypted data is empty but encryptedBytes.length is ${encryptedBytes.length}');
232-
await FileManager.writeFile(file.relativeLocalPath, decryptedData,
233-
alsoUpload: false, lastModified: file.remoteFile?.lastModified); // write remote file to local and set time stamp from remote file!
229+
await FileManager.writeFile(
230+
file.relativeLocalPath,
231+
decryptedData,
232+
alsoUpload: false,
233+
// Local file should have the same last modified date as remote
234+
lastModified: file.remoteFile?.lastModified,
235+
);
234236
}
235237

236238
@override

0 commit comments

Comments
 (0)