9
9
#include " Pipe/Extern/portable-file-dialogs.h"
10
10
#include " Pipe/Files/Paths.h"
11
11
12
- #include < efsw/efsw.hpp>
13
12
#include < shared_mutex>
14
13
15
14
@@ -273,6 +272,7 @@ namespace p
273
272
}
274
273
275
274
void Init (StringView path);
275
+ void SetPath (StringView newPath);
276
276
bool Exists ();
277
277
void Scan (DirectorySnapshotDiff& diff);
278
278
FileStatusMap::Iterator NodeInFiles (FileStatus& fi);
@@ -286,11 +286,36 @@ namespace p
286
286
void DeleteAll (DirectorySnapshotDiff& diff);
287
287
};
288
288
289
+ void DirectorySnapshotDiff::Clear ()
290
+ {
291
+ filesCreated.Clear ();
292
+ filesModified.Clear ();
293
+ filesMoved.Clear ();
294
+ filesDeleted.Clear ();
295
+ dirsCreated.Clear ();
296
+ dirsModified.Clear ();
297
+ dirsMoved.Clear ();
298
+ dirsDeleted.Clear ();
299
+ }
300
+
301
+ bool DirectorySnapshotDiff::Changed ()
302
+ {
303
+ return !filesCreated.IsEmpty () || !filesModified.IsEmpty () || !filesMoved.IsEmpty ()
304
+ || !filesDeleted.IsEmpty () || !dirsCreated.IsEmpty () || !dirsModified.IsEmpty ()
305
+ || !dirsMoved.IsEmpty () || !dirsDeleted.IsEmpty ();
306
+ }
307
+
308
+
289
309
void DirectorySnapshot::Init (StringView newPath)
310
+ {
311
+ SetPath (newPath);
312
+ InitFiles ();
313
+ }
314
+
315
+ void DirectorySnapshot::SetPath (StringView newPath)
290
316
{
291
317
path = String{newPath};
292
318
pathFileState = GetFileStatus (path);
293
- InitFiles ();
294
319
}
295
320
296
321
bool DirectorySnapshot::Exists ()
@@ -720,9 +745,8 @@ namespace p
720
745
// / Is this a recursive watch?
721
746
if (watch->path != path)
722
747
{
723
- if (!(path.size ()
724
- && (path.at (0 ) == FileSystem::getOSSlash ()
725
- || path.at (path.size () - 1 ) == FileSystem::getOSSlash ())))
748
+ if (path.empty ()
749
+ || (!IsSeparator (path.at (0 )) && !IsSeparator (path.at (path.size () - 1 ))))
726
750
{
727
751
// / Get the real directory
728
752
if (parent)
@@ -736,7 +760,7 @@ namespace p
736
760
}
737
761
}
738
762
739
- dirSnap.SetDirectoryInfo (pathTmp);
763
+ dirSnap.SetPath (pathTmp);
740
764
}
741
765
742
766
void GenericDirWatch::HandleAction (
@@ -783,7 +807,8 @@ namespace p
783
807
}
784
808
else
785
809
{
786
- dir = link;
810
+ path = link;
811
+ dir = Tag{link};
787
812
}
788
813
}
789
814
else
@@ -898,36 +923,22 @@ namespace p
898
923
path = path.substr (dirSnap.path .size () - 1 );
899
924
}
900
925
901
- if (path.size () == 1 )
902
- {
903
- P_Check (path[0 ] == FileSystem::getOSSlash ());
904
- return this ;
905
- }
906
-
907
- size_t level = 0 ;
908
- std::vector<String> dirv = String::split (path, FileSystem::getOSSlash (), false );
909
-
910
926
GenericDirWatch* dirWatcher = this ;
911
-
912
- while (level < dirv. size () )
927
+ const PathIterator dirEnd = PathIterator::CreateEnd (path);
928
+ for ( auto dirIt = PathIterator::CreateBegin (path); dirIt != dirEnd; ++dirIt )
913
929
{
914
930
// search the dir level in the current watcher
915
- auto it = dirWatcher->directories .FindIt (Tag{dirv[level] });
931
+ auto it = dirWatcher->directories .FindIt (Tag{*dirIt });
916
932
917
- // found? continue with the next level
918
- if (it != dirWatcher->directories .end ())
919
- {
920
- dirWatcher = it->second ;
921
- ++level;
922
- }
923
- else
933
+ if (it == dirWatcher->directories .end ())
924
934
{
925
935
// couldn't found the folder level?
926
936
// directory not watched
927
937
return nullptr ;
928
938
}
939
+ // found? continue with the next level
940
+ dirWatcher = it->second ;
929
941
}
930
-
931
942
return dirWatcher;
932
943
}
933
944
@@ -1271,7 +1282,7 @@ namespace p
1271
1282
else
1272
1283
{
1273
1284
fileWatcher = MakeOwned<DefaultFileWatcher>(this );
1274
- if (!fileWatcher.Get <BaseFileWatcher>()
1285
+ if (!fileWatcher.GetUnsafe <BaseFileWatcher>()
1275
1286
->IsInitialized ()) // Fallback to generic file watcher
1276
1287
{
1277
1288
p::Warning (" Initialization of OS file watcher failed. Fallback to generic." );
@@ -1286,22 +1297,22 @@ namespace p
1286
1297
1287
1298
void FileWatcher::StartWatchingAsync ()
1288
1299
{
1289
- fileWatcher.Get <BaseFileWatcher>()->Watch ();
1300
+ fileWatcher.GetUnsafe <BaseFileWatcher>()->Watch ();
1290
1301
}
1291
1302
1292
1303
FileWatchId FileWatcher::ListenPath (StringView path, bool recursive, FileWatchCallback callback)
1293
1304
{
1294
- return fileWatcher.Get <BaseFileWatcher>()->AddWatch (path, Move (callback), recursive);
1305
+ return fileWatcher.GetUnsafe <BaseFileWatcher>()->AddWatch (path, Move (callback), recursive);
1295
1306
}
1296
1307
1297
1308
void FileWatcher::StopListening (FileWatchId id)
1298
1309
{
1299
- fileWatcher.Get <BaseFileWatcher>()->RemoveWatch (id);
1310
+ fileWatcher.GetUnsafe <BaseFileWatcher>()->RemoveWatch (id);
1300
1311
}
1301
1312
1302
1313
void FileWatcher::Reset ()
1303
1314
{
1304
- fileWatcher.Get <BaseFileWatcher>()->RemoveAllWatches ();
1315
+ fileWatcher.GetUnsafe <BaseFileWatcher>()->RemoveAllWatches ();
1305
1316
}
1306
1317
#pragma endregion FileWatch
1307
1318
} // namespace p
0 commit comments