File tree 4 files changed +22
-16
lines changed
4 files changed +22
-16
lines changed Original file line number Diff line number Diff line change @@ -72,11 +72,11 @@ public void RefreshFiles()
72
72
Files . Clear ( ) ;
73
73
Files . AddRange (
74
74
folder . GetFiles ( )
75
- . Where ( f => Filter . ShouldIgnore ( f . FullName ) == false )
75
+ . Where ( f => Filter . Include ( f . FullName ) )
76
76
. Select (
77
77
f => new FileItem (
78
78
Path . GetRelativePath ( WorkBase , f . FullName )
79
- ) . Read ( _logger )
79
+ ) . Read ( WorkBase , _logger )
80
80
)
81
81
. Where ( f => f . Hash is not null )
82
82
) ;
@@ -89,11 +89,11 @@ public void RefreshFiles()
89
89
foldersToSearch . Enqueue ( dir ) ;
90
90
Files . AddRange (
91
91
subFolder . GetFiles ( )
92
- . Where ( f => Filter . ShouldIgnore ( f . FullName ) == false )
92
+ . Where ( f => Filter . Include ( f . FullName ) )
93
93
. Select (
94
94
f => new FileItem (
95
95
Path . GetRelativePath ( WorkBase , f . FullName )
96
- ) . Read ( _logger )
96
+ ) . Read ( WorkBase , _logger )
97
97
)
98
98
. Where ( f => f . Hash is not null )
99
99
) ;
Original file line number Diff line number Diff line change @@ -15,21 +15,21 @@ public FileItem(string path)
15
15
Path = path ;
16
16
}
17
17
18
- public FileItem Read ( ILogger logger )
18
+ public FileItem Read ( string workBase , ILogger logger )
19
19
{
20
20
// Avoid file not exists exception, sometimes IDE creates temporary files
21
21
try
22
22
{
23
23
Policy . Handle < Exception > ( ) . Retry ( 3 , ( exception , retryCount ) =>
24
24
{
25
25
logger . LogError (
26
- "Error loading sync ignore file: {message}, try times: {retryCount}" ,
26
+ "Error loading file: {message}, try times: {retryCount}" ,
27
27
exception . Message ,
28
28
retryCount
29
29
) ;
30
30
} ) . Execute ( ( ) =>
31
31
{
32
- var content = File . ReadAllText ( Path ) ;
32
+ var content = File . ReadAllText ( System . IO . Path . Combine ( workBase , Path ) ) ;
33
33
var hash = SHA256 . HashData ( Encoding . UTF8 . GetBytes ( content ) ) ;
34
34
Hash = Convert . ToBase64String ( hash ) ;
35
35
} ) ;
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ public class FilesFilter
8
8
9
9
public readonly List < string > IgnoredPaths = [ ] ;
10
10
11
- public string WorkBase { get ; init ; }
11
+ public string WorkBase { get ; }
12
12
13
13
private bool _configFileExists = true ;
14
14
@@ -20,7 +20,7 @@ public FilesFilter(string workBase, ILogger logger)
20
20
21
21
WorkBase = workBase ;
22
22
23
- LoadIgnoreConfig ( ) ;
23
+ _ = LoadIgnoreConfig ( ) ;
24
24
}
25
25
26
26
public FilesFilter LoadIgnoreConfig ( )
@@ -30,7 +30,7 @@ public FilesFilter LoadIgnoreConfig()
30
30
31
31
var path = Path . Combine ( WorkBase , ".sync-ignore" ) ;
32
32
33
- if ( ! File . Exists ( path ) )
33
+ if ( File . Exists ( path ) == false )
34
34
{
35
35
_configFileExists = false ;
36
36
return this ;
@@ -71,7 +71,7 @@ public FilesFilter LoadIgnoreConfig()
71
71
return this ;
72
72
}
73
73
74
- public bool ShouldIgnore ( string path )
74
+ private bool ShouldIgnore ( string path )
75
75
{
76
76
if ( _configFileExists == false ) return false ;
77
77
@@ -87,4 +87,6 @@ public bool ShouldIgnore(string path)
87
87
88
88
return false ;
89
89
}
90
+
91
+ public bool Include ( string path ) => ! ShouldIgnore ( path ) ;
90
92
}
Original file line number Diff line number Diff line change 35
35
context . InitializeFileSystemWatcher (
36
36
( e ) =>
37
37
{
38
- if ( context . Filter . ShouldIgnore ( e . FullPath ) == false )
38
+ if ( context . Filter . Include ( e . FullPath ) )
39
39
app . Logger . LogInformation (
40
40
"[{time}] FileSystem Modified: {name}, {changeType} | {path}" ,
41
41
DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) ,
@@ -88,10 +88,14 @@ void RunServer(Context context)
88
88
89
89
app . MapGet (
90
90
"/file/{path}" ,
91
- ( string path ) => context . GetFile (
92
- Encoding . UTF8 . GetString (
93
- Convert . FromBase64String ( path )
94
- )
91
+ ( string path ) => Results . Content (
92
+ context . GetFile (
93
+ Encoding . UTF8 . GetString (
94
+ Convert . FromBase64String ( path )
95
+ )
96
+ ) ,
97
+ "text/plain" ,
98
+ Encoding . UTF8
95
99
)
96
100
) ;
97
101
You can’t perform that action at this time.
0 commit comments