Fixed bug: DisableVfsForThisThread made VFS control API to fail

This commit is contained in:
Berserker 2019-05-25 20:57:47 +03:00
parent d67a8ae4f9
commit 7cb8c94406
2 changed files with 66 additions and 82 deletions

View File

@ -343,55 +343,49 @@ end;
function RunVfs (DirListingOrder: TDirListingSortType): boolean; function RunVfs (DirListingOrder: TDirListingSortType): boolean;
begin begin
result := not DisableVfsForThisThread; result := true;
if result then begin with VfsCritSection do begin
with VfsCritSection do begin Enter;
Enter;
if not VfsIsRunning then begin if not VfsIsRunning then begin
if not VfsTreeIsBuilt then begin if not VfsTreeIsBuilt then begin
VfsDirListingOrder := DirListingOrder; VfsDirListingOrder := DirListingOrder;
BuildVfsItemsTree(); BuildVfsItemsTree();
SortVfsDirListings(DirListingOrder); SortVfsDirListings(DirListingOrder);
VfsTreeIsBuilt := true; VfsTreeIsBuilt := true;
end;
VfsIsRunning := true;
end; end;
VfsIsRunning := true;
end;
Leave; Leave;
end; // .with end; // .with
end; // .if
end; // .function RunVfs end; // .function RunVfs
function PauseVfs: LONGBOOL; stdcall; function PauseVfs: LONGBOOL; stdcall;
begin begin
result := not DisableVfsForThisThread; result := true;
if result then begin with VfsCritSection do begin
with VfsCritSection do begin Enter;
Enter; VfsIsRunning := false;
VfsIsRunning := false; Leave;
Leave;
end;
end; end;
end; end;
function ResetVfs: LONGBOOL; stdcall; function ResetVfs: LONGBOOL; stdcall;
begin begin
result := not DisableVfsForThisThread; result := true;
if result then begin with VfsCritSection do begin
with VfsCritSection do begin Enter;
Enter; VfsItems.Clear;
VfsItems.Clear; MappedFiles.Clear;
MappedFiles.Clear; Mappings.Clear;
Mappings.Clear; VfsIsRunning := false;
VfsIsRunning := false; VfsTreeIsBuilt := false;
VfsTreeIsBuilt := false; Leave;
Leave;
end;
end; end;
end; end;
@ -631,37 +625,33 @@ var
i: integer; i: integer;
begin begin
result := not DisableVfsForThisThread; with VfsCritSection do begin
Enter;
result := VfsTreeIsBuilt;
if result then begin if result then begin
with VfsCritSection do begin VfsItems.Clear;
Enter; MappedFiles.Clear;
result := VfsTreeIsBuilt; VfsWasRunning := VfsIsRunning;
VfsIsRunning := false;
VfsTreeIsBuilt := false;
if result then begin for i := 0 to Mappings.Count - 1 do begin
VfsItems.Clear; with TMapping(Mappings[i]) do begin
MappedFiles.Clear; MapDir(AbsVirtPath, AbsRealPath, OverwriteExisting, Flags);
VfsWasRunning := VfsIsRunning;
VfsIsRunning := false;
VfsTreeIsBuilt := false;
for i := 0 to Mappings.Count - 1 do begin
with TMapping(Mappings[i]) do begin
MapDir(AbsVirtPath, AbsRealPath, OverwriteExisting, Flags);
end;
end;
if VfsWasRunning then begin
BuildVfsItemsTree();
SortVfsDirListings(VfsDirListingOrder);
VfsTreeIsBuilt := true;
VfsIsRunning := true;
end; end;
end; end;
Leave; if VfsWasRunning then begin
end; // .with BuildVfsItemsTree();
end; // .if SortVfsDirListings(VfsDirListingOrder);
VfsTreeIsBuilt := true;
VfsIsRunning := true;
end;
end;
Leave;
end; // .with
end; // .function RefreshVfs end; // .function RefreshVfs
function RefreshMappedFile (const FilePath: WideString): boolean; function RefreshMappedFile (const FilePath: WideString): boolean;
@ -674,30 +664,26 @@ var
begin begin
VfsItem := nil; VfsItem := nil;
// * * * * * // // * * * * * //
result := not DisableVfsForThisThread; with VfsCritSection do begin
Enter;
result := VfsTreeIsBuilt;
if result then begin if result then begin
with VfsCritSection do begin VfsWasRunning := VfsIsRunning;
Enter; VfsIsRunning := false;
result := VfsTreeIsBuilt; AbsRealPath := NormalizePath(FilePath);
VfsItem := TVfsItem(MappedFiles[WideStrToCaselessKey(AbsRealPath)]);
result := (VfsItem <> nil) and GetFileInfo(AbsRealPath, FileInfo);
if result then begin if result then begin
VfsWasRunning := VfsIsRunning; CopyFileInfoWithoutNames(FileInfo.Base, VfsItem.Info.Base);
VfsIsRunning := false;
AbsRealPath := NormalizePath(FilePath);
VfsItem := TVfsItem(MappedFiles[WideStrToCaselessKey(AbsRealPath)]);
result := (VfsItem <> nil) and GetFileInfo(AbsRealPath, FileInfo);
if result then begin
CopyFileInfoWithoutNames(FileInfo.Base, VfsItem.Info.Base);
end;
VfsIsRunning := VfsWasRunning;
end; end;
Leave; VfsIsRunning := VfsWasRunning;
end; // .with end;
end; // .if
Leave;
end; // .with
end; // .function RefreshMappedFile end; // .function RefreshMappedFile
begin begin

View File

@ -10,7 +10,7 @@ unit VfsWatching;
uses uses
Windows, SysUtils, Math, Windows, SysUtils, Math,
Utils, Concur, WinUtils, StrLib, WinNative, Utils, Concur, WinUtils, StrLib, WinNative,
VfsBase, VfsUtils, {FIXME} DlgMes; VfsBase, VfsUtils;
(* Spawns separate thread, which starts recursive monitoring for changes in specified directory. (* Spawns separate thread, which starts recursive monitoring for changes in specified directory.
@ -253,7 +253,6 @@ begin
if NeedFullRescan and (PlannedRescanTime <= CurrentTime) then begin if NeedFullRescan and (PlannedRescanTime <= CurrentTime) then begin
VfsBase.RefreshVfs; VfsBase.RefreshVfs;
NeedFullRescan := false; NeedFullRescan := false;
VarDump(['Fully rescanned']);
end; end;
if DirChangesScanner = nil then begin if DirChangesScanner = nil then begin
@ -283,7 +282,6 @@ begin
end else if DirChange.Action = NOTIFY_FILE_MODIFIED then begin end else if DirChange.Action = NOTIFY_FILE_MODIFIED then begin
if not NeedFullRescan then begin if not NeedFullRescan then begin
VfsBase.RefreshMappedFile(DirChange.FilePath); VfsBase.RefreshMappedFile(DirChange.FilePath);
VarDump(['Updated ' + DirChange.FilePath]);
end; end;
LastChangeTime := WinUtils.GetMicroTime; LastChangeTime := WinUtils.GetMicroTime;