1
1
//
2
- // Copyright (c) Roland Pihlakas 2019 - 2022
2
+ // Copyright (c) Roland Pihlakas 2019 - 2023
3
3
4
4
//
5
5
// Roland Pihlakas licenses this file to you under the GNU Lesser General Public License, ver 2.1.
@@ -43,7 +43,7 @@ public static async Task<Dictionary<string, CachedFileInfo>> ReadFileInfoCache(s
43
43
44
44
if ( await Extensions . FSOperation
45
45
(
46
- ( ) => File . Exists ( cacheFileName ) ,
46
+ cancellationAndTimeoutToken => File . Exists ( cacheFileName ) ,
47
47
cacheFileName ,
48
48
Global . CancellationToken . Token ,
49
49
timeout : 0 , //NB!
@@ -101,7 +101,7 @@ public static async Task SaveFileInfoCache(Dictionary<string, CachedFileInfo> di
101
101
102
102
if ( ! await Extensions . FSOperation
103
103
(
104
- ( ) => Directory . Exists ( cacheDirName ) ,
104
+ cancellationAndTimeoutToken => Directory . Exists ( cacheDirName ) ,
105
105
cacheDirName ,
106
106
Global . CancellationToken . Token ,
107
107
timeout : 0 , //NB!
@@ -110,7 +110,7 @@ public static async Task SaveFileInfoCache(Dictionary<string, CachedFileInfo> di
110
110
{
111
111
await Extensions . FSOperation
112
112
(
113
- ( ) => Directory . CreateDirectory ( cacheDirName ) ,
113
+ cancellationAndTimeoutToken => Directory . CreateDirectory ( cacheDirName ) ,
114
114
cacheDirName ,
115
115
Global . CancellationToken . Token ,
116
116
timeout : 0 , //NB!
@@ -127,6 +127,7 @@ await FileExtensions.WriteAllBytesAsync
127
127
serialisedData ,
128
128
createTempFileFirst : true ,
129
129
cancellationToken : Global . CancellationToken . Token ,
130
+ retryCount : 5 , //TODO: config
130
131
timeout : 0 , //NB!
131
132
suppressLongRunningOperationMessage : true //NB!
132
133
) ;
@@ -137,6 +138,8 @@ await FileExtensions.WriteAllBytesAsync
137
138
public static async Task RefreshFileInfo ( WatcherContext context )
138
139
{
139
140
var fileInfo = context . Event . FileSystemInfo as FileInfo ;
141
+ //var fileInfo = context.Event.FileSystemInfo.AsFileInfo(); // as FileInfo;
142
+
140
143
if ( fileInfo != null && ! context . FileInfoRefreshed . Value )
141
144
//var fileInfo = context.FileInfo;
142
145
//if (!context.FileInfoRefreshed.Value)
@@ -145,7 +148,7 @@ public static async Task RefreshFileInfo(WatcherContext context)
145
148
146
149
await Extensions . FSOperation
147
150
(
148
- ( ) =>
151
+ cancellationAndTimeoutToken =>
149
152
{
150
153
fileInfo . Refresh ( ) ; //https://stackoverflow.com/questions/7828132/getting-current-file-length-fileinfo-length-caching-and-stale-information
151
154
if ( fileInfo . Exists )
@@ -227,7 +230,7 @@ internal static async Task SaveFileInfo(string fileName, CachedFileInfo fileInfo
227
230
if ( Global . PersistentCacheDestAndHistoryFolders && removed1 )
228
231
{
229
232
if ( dirName == null )
230
- dirName = Path . GetDirectoryName ( fileName ) ;
233
+ dirName = FolderSyncNetSource . Path . GetDirectoryName ( fileName ) ;
231
234
232
235
dirName = Extensions . GetLongPath ( Extensions . GetDirPathWithTrailingSlash ( dirName ) ) ;
233
236
@@ -249,7 +252,7 @@ internal static async Task SaveFileInfo(string fileName, CachedFileInfo fileInfo
249
252
}
250
253
#endif
251
254
}
252
- else
255
+ else //if (fileInfo == null)
253
256
{
254
257
var fullName = Extensions . GetLongPath ( fileName ) ;
255
258
Global . DestAndHistoryFileInfoCache [ fullName . ToUpperInvariantOnWindows ( ) ] = fileInfo ;
@@ -258,7 +261,7 @@ internal static async Task SaveFileInfo(string fileName, CachedFileInfo fileInfo
258
261
if ( Global . PersistentCacheDestAndHistoryFolders )
259
262
{
260
263
if ( dirName == null )
261
- dirName = Path . GetDirectoryName ( fileName ) ;
264
+ dirName = FolderSyncNetSource . Path . GetDirectoryName ( fileName ) ;
262
265
263
266
dirName = Extensions . GetLongPath ( Extensions . GetDirPathWithTrailingSlash ( dirName ) ) ;
264
267
@@ -275,7 +278,7 @@ internal static async Task SaveFileInfo(string fileName, CachedFileInfo fileInfo
275
278
}
276
279
}
277
280
}
278
- }
281
+ } //if (fileInfo == null)
279
282
} //internal static async Task SaveFileInfo(string fileName, CachedFileInfo fileInfo, CancellationToken cancellationToken = default(CancellationToken))
280
283
281
284
private static Task < CachedFileInfo > GetFileInfo ( WatcherContext context )
@@ -305,7 +308,7 @@ private static async Task<CachedFileInfo> GetFileInfo(string fullName, Cancellat
305
308
306
309
var fileInfo = await Extensions . FSOperation
307
310
(
308
- ( ) =>
311
+ cancellationAndTimeoutToken =>
309
312
{
310
313
var fileInfo1 = new FileInfo ( fullName ) ;
311
314
@@ -452,7 +455,10 @@ private static async Task<long> GetFileSize(FileInfoRef otherFileInfo, string ot
452
455
453
456
//NB! no RefreshFileInfo or GetFileExists calls here
454
457
455
- return otherFileInfo . Value . Length . Value ;
458
+ if ( ! otherFileInfo . Value . Exists . Value )
459
+ return - 1 ;
460
+ else
461
+ return otherFileInfo . Value . Length . Value ;
456
462
}
457
463
458
464
public static async Task InvalidateFileDataInPersistentCache ( WatcherContext context )
@@ -466,14 +472,14 @@ public static async Task InvalidateFileDataInPersistentCache(WatcherContext cont
466
472
var otherFullName = await GetOtherFullName ( context ) ;
467
473
var longOtherFullName = Extensions . GetLongPath ( otherFullName ) ;
468
474
469
- var otherDirName = Extensions . GetDirPathWithTrailingSlash ( Path . GetDirectoryName ( otherFullName ) ) ;
475
+ var otherDirName = Extensions . GetDirPathWithTrailingSlash ( FolderSyncNetSource . Path . GetDirectoryName ( otherFullName ) ) ;
470
476
var longOtherDirName = Extensions . GetLongPath ( otherDirName ) ;
471
477
472
478
using ( await Global . PersistentCacheLocks . LockAsync ( longOtherDirName . ToUpperInvariantOnWindows ( ) , context . Token ) )
473
479
{
474
480
var cachedFileInfos = await ReadFileInfoCache ( longOtherDirName , context . ForHistory ) ;
475
481
476
- if ( cachedFileInfos != null )
482
+ if ( cachedFileInfos != null ) //TODO: if cachedFileInfos == null then scan entire folder and create cached file infos file
477
483
{
478
484
cachedFileInfos . Remove ( GetNonFullName ( longOtherFullName ) . ToUpperInvariantOnWindows ( ) ) ;
479
485
0 commit comments