summaryrefslogtreecommitdiff
path: root/vfs/UVFSCore.pas
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2009-11-28 16:00:34 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2009-11-28 16:00:34 +0100
commit6132c2ef3066e813acb1237afeca266f32c53a21 (patch)
treeb880a4eeb74e07f0e94c9767f9aba0873194d903 /vfs/UVFSCore.pas
parent9e4a6521a9ea3310437962d6708cf814fafc70d1 (diff)
downloadtuxcmd-6132c2ef3066e813acb1237afeca266f32c53a21.tar.xz
Engine and VFS API cleanupv0.6.72
* also split threaded operations into UCoreWorkers.pas * symlinks should be properly resolved now, even in archives * no more relative/absolute path confusion * moved FillDirFiles outside engines, made it more universal
Diffstat (limited to 'vfs/UVFSCore.pas')
-rw-r--r--vfs/UVFSCore.pas541
1 files changed, 182 insertions, 359 deletions
diff --git a/vfs/UVFSCore.pas b/vfs/UVFSCore.pas
index a4bedf0..90b31b5 100644
--- a/vfs/UVFSCore.pas
+++ b/vfs/UVFSCore.pas
@@ -21,7 +21,7 @@ unit UVFSCore;
interface
-uses GTKForms, ULibc, Classes, uVFSprototypes, UEngines, UCoreUtils;
+uses GTKForms, ULibc, glib2, Classes, uVFSprototypes, UEngines, UCoreUtils;
type
@@ -40,9 +40,7 @@ type
FVFSChangeDir: TVFSChangeDir;
FVFSGetPath: TVFSGetPath;
FVFSGetPathURI: TVFSGetPathURI;
- FVFSGetFileSystemSize: TVFSGetFileSystemSize;
- FVFSGetFileSystemFree: TVFSGetFileSystemFree;
- FVFSFileExists: TVFSFileExists;
+ FVFSGetFileSystemInfo: TVFSGetFileSystemInfo;
FVFSFileInfo: TVFSFileInfo;
FVFSMkDir: TVFSMkDir;
FVFSRemove: TVFSRemove;
@@ -90,13 +88,14 @@ type
TVFSEngine = class(TPanelEngine)
private
+ BreakProcessingType: integer;
FGlobs: Pointer;
FSourcePlugin: TVFSPlugin;
FBlockSize: Cardinal;
- BreakProcessingKind: integer;
FArchiveMode: boolean;
FArchivePath: string;
function GetPluginID: string;
+ function GetDataItemFromVFSItem(P: PVFSItem): PDataItem;
public
Password: string;
PasswordUsed: boolean;
@@ -104,58 +103,60 @@ type
OpenedFromQuickConnect: boolean;
CustomPluginIDSave: string;
constructor Create(SourcePlugin: TVFSPlugin);
- function VFSOpenURI(URI: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
- function VFSOpenEx(OpenFile: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): TVFSResult;
- function VFSClose: boolean;
-
destructor Destroy; override;
- function GetListing(var List: TList; const AddDotFiles: boolean): integer; override;
- function GetListing(var List: TList; const AddDotFiles: boolean; APath: string): integer; override;
+
+ function GetListing(List: TList; const APath: string; AddDotFiles, FollowSymlinks, AddFullPath: boolean): integer; override;
+ function GetFileInfo(const APath: string; FollowSymlinks, AddFullPath: boolean): PDataItem; override;
+
function ChangeDir(const NewPath: string): integer; override;
- function ChangeDirEx(const NewPath: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): integer;
- function ExplicitChDir(const NewPath: string): integer; override;
- function GetFileSystemSize: Int64; override;
- function GetFileSystemSize(const APath: string): Int64; override;
- function GetFileSystemFree: Int64; override;
- function GetFileSystemFree(const APath: string): Int64; override;
- function MakeDir(const NewDir: string): integer; override;
- function GetDirSize(APath: string): Int64; override;
- function Remove(APath: string): integer; override;
- procedure FillDirFiles(APath: string; List: TList; ALevel: word); override;
- function GetFileInfoSL(APath: string): PDataItemSL; override;
- function FileExists(const FileName: string; const Use_lstat: boolean = False): Boolean; override;
- function DirectoryExists(const FileName: string; const Use_lstat: boolean = False): Boolean; override;
- function MakeSymLink(const NewFileName, PointTo: string): integer; override;
- function Chmod(const FileName: string; const Mode: integer): integer; override;
- function Chown(const FileName: string; const UID, GID: integer): integer; override;
+ function GetPath: string; override;
+ procedure SetPath(Value: string); override;
+
+ function GetDirSize(const APath: string): Int64; override;
procedure BreakProcessing(ProcessingKind: integer); override;
- function RenameFile(SourceFile, DestFile: string): integer; override;
- function ChangeTimes(APath: string; mtime, atime: Int64): integer; override;
+ function FileExists(const FileName: string; FollowSymlinks: boolean): boolean; override;
+ function DirectoryExists(const FileName: string; FollowSymlinks: boolean): boolean; override;
procedure GetFileSystemInfo(const APath: string; var FSSize, FSFree: Int64; var FSName: string); override;
- function OpenFile(const APath: string; Mode: integer; var Error: integer): TEngineFileDes; override;
+ function IsOnROMedium(const FileName: string): boolean; override;
+ function FileCanRun(const FileName: string): boolean; override;
+
+ function MakeDir(const NewDir: string): integer; override;
+ function Remove(const APath: string): integer; override;
+ function MakeSymLink(const NewFileName, PointTo: string): integer; override;
+ function Chmod(const FileName: string; Mode: cuLong): integer; override;
+ function Chown(const FileName: string; UID, GID: cuLong): integer; override;
+ function RenameFile(const SourceFile, DestFile: string): integer; override;
+ function ChangeTimes(const APath: string; mtime, atime: time_t): integer; override;
+
+ function GetBlockSize: guint32; override;
+ procedure SetBlockSize(Value: guint32); override;
+ function CopyFileIn(Sender: Pointer; const SourceFile, DestFile: string; ProgressFunc: TEngineProgressFunc; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean; override;
+ function CopyFileOut(Sender: Pointer; const SourceFile, DestFile: string; ProgressFunc: TEngineProgressFunc; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean; override;
+ function IsOnSameFS(const Path1, Path2: string; FollowSymlinks: boolean): boolean; override;
+ function TwoSameFiles(const Path1, Path2: string; FollowSymlinks: boolean): boolean; override;
+
+ function OpenFile(const APath: string; Mode: integer; var Error: integer): TEngineFileDes; override;
function ReadFile(const FileDescriptor: TEngineFileDes; Buffer: Pointer; ABlockSize: integer; var Error: integer): integer; override;
function WriteFile(const FileDescriptor: TEngineFileDes; Buffer: Pointer; BytesCount: integer; var Error: integer): integer; override;
function CloseFile(const FileDescriptor: TEngineFileDes): integer; override;
function FileSeek(const FileDescriptor: TEngineFileDes; const AbsoluteOffset: Int64; var Error: integer): Int64; override;
- function IsOnROMedium(const FileName: string): boolean; override;
- function FileCanRun(const FileName: string): boolean; override;
- function GetPath: string; override;
- procedure SetPath(Value: string); override;
- function GetPathURI: string;
- function GetBlockSize: Cardinal; override;
- procedure SetBlockSize(Value: Cardinal); override;
- function CopyFileIn(Sender: Pointer; SourceFile, DestFile: string; ProgressFunc: TEngineProgressFunc; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean; override;
- function CopyFileOut(Sender: Pointer; SourceFile, DestFile: string; ProgressFunc: TEngineProgressFunc; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean; override;
- function CopyFileInEx(Sender: Pointer; SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc; Append: boolean;
- AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
- function CopyFileOutEx(Sender: Pointer; SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc; Append: boolean;
- AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
- function IsOnSameFS(const Path1, Path2: string): boolean; override;
- function TwoSameFiles(const Path1, Path2: string): boolean; override;
+ // VFS additions
+ function VFSOpenURI(const URI: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
+ function VFSOpenEx(const OpenFile: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): TVFSResult;
+ function VFSClose: boolean;
+ function ChangeDirEx(const NewPath: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): integer;
+
+ function GetPathURI: string;
function GetPasswordRequired: boolean;
procedure ResetPassword;
+
+ // the callbacks here are used for next volume prompts, password prompts (encrypted archives) - as long as this is specific to each file
+ function CopyFileInEx(Sender: Pointer; const SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc; Append: boolean;
+ AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
+ function CopyFileOutEx(Sender: Pointer; const SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc; Append: boolean;
+ AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
published
property Path: string read GetPath write SetPath;
property BlockSize: Cardinal read GetBlockSize write SetBlockSize;
@@ -215,9 +216,7 @@ begin
@FVFSGetPath := dlsym(ModuleHandle, 'VFSGetPath');
@FVFSGetPathURI := dlsym(ModuleHandle, 'VFSGetPathURI');
@FVFSChangeDir := dlsym(ModuleHandle, 'VFSChangeDir');
- @FVFSGetFileSystemSize := dlsym(ModuleHandle, 'VFSGetFileSystemSize');
- @FVFSGetFileSystemFree := dlsym(ModuleHandle, 'VFSGetFileSystemFree');
- @FVFSFileExists := dlsym(ModuleHandle, 'VFSFileExists');
+ @FVFSGetFileSystemInfo := dlsym(ModuleHandle, 'VFSGetFileSystemInfo');
@FVFSFileInfo := dlsym(ModuleHandle, 'VFSFileInfo');
@FVFSMkDir := dlsym(ModuleHandle, 'VFSMkDir');
@FVFSRemove := dlsym(ModuleHandle, 'VFSRemove');
@@ -343,11 +342,11 @@ end;
constructor TVFSEngine.Create(SourcePlugin: TVFSPlugin);
begin
inherited Create;
+ BreakProcessingType := 0;
FSourcePlugin := SourcePlugin;
FBlockSize := 65536;
FArchiveMode := False;
FArchivePath := '';
- BreakProcessingKind := 0;
FGlobs := nil;
Password := '';
PasswordUsed := False;
@@ -370,7 +369,7 @@ begin
end;
end;
-function TVFSEngine.VFSOpenURI(URI: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
+function TVFSEngine.VFSOpenURI(const URI: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
begin
Result := False;
if (FGlobs <> nil) and (@FSourcePlugin.FVFSOpenURI <> nil) then begin
@@ -384,7 +383,7 @@ begin
end;
end;
-function TVFSEngine.VFSOpenEx(OpenFile: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): TVFSResult;
+function TVFSEngine.VFSOpenEx(const OpenFile: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): TVFSResult;
begin
Result := cVFS_OK;
if (FGlobs <> nil) and (@FSourcePlugin.FVFSOpenArchive <> nil) then begin
@@ -399,6 +398,7 @@ begin
end;
end;
+(********************************************************************************************************************************)
function TVFSEngine.VFSClose: boolean;
begin
Result := False;
@@ -406,20 +406,52 @@ begin
then Result := FSourcePlugin.FVFSClose(FGlobs) = cVFS_OK;
end;
-function TVFSEngine.GetListing(var List: TList; const AddDotFiles: boolean; APath: string): integer;
+function TVFSEngine.GetDataItemFromVFSItem(P: PVFSItem): PDataItem;
+var Item: PDataItem;
+begin
+ Item := malloc(sizeof(TDataItem));
+ memset(Item, 0, sizeof(TDataItem));
+ Item^.UpDir := False;
+ Item^.Selected := False;
+
+ Item^.FName := g_strdup(P^.FName);
+ Item^.FDisplayName := g_strdup(P^.FDisplayName);
+ Item^.LnkPointTo := g_strdup(P^.sLinkTo);
+ Item^.Mode := P^.iMode;
+ Item^.IsDotFile := (Length(P^.FName) > 1) and (P^.FName[0] = '.');
+ Item^.IsExecutable := (P^.iMode and S_IXUSR) = S_IXUSR;
+ Item^.IsDir := TVFSItemType(P^.ItemType) = vDirectory;
+ Item^.IsLnk := P^.IsLink;
+ Item^.IsBlk := TVFSItemType(P^.ItemType) = vBlockdev;
+ Item^.IsChr := TVFSItemType(P^.ItemType) = vChardev;
+ Item^.IsFIFO := TVFSItemType(P^.ItemType) = vFifo;
+ Item^.IsSock := TVFSItemType(P^.ItemType) = vSock;
+ Item^.mtime := P^.m_time;
+ Item^.atime := P^.a_time;
+ Item^.ctime := P^.c_time;
+ Item^.UID := P^.iUID;
+ Item^.GID := P^.iGID;
+ Item^.Size := P^.iSize;
+ Item^.PackedSize := P^.iPackedSize;
+
+ Result := Item;
+end;
+
+function TVFSEngine.GetListing(List: TList; const APath: string; AddDotFiles, FollowSymlinks, AddFullPath: boolean): integer;
var P: PVFSItem;
Item: PDataItem;
- i, Res: integer;
+ Res: integer;
begin
DebugMsg(['^^VFS (II): GetListing begin']);
Result := 0;
try
- if @FSourcePlugin.FVFSListFirst = nil then Exit;
- P := real_libc_malloc(SizeOf(TVFSItem));
- memset(P, 0, SizeOf(TVFSItem));
-// DebugMsg(['Item = ', Int64(P)]);
-// DebugMsg(['FVFSListFirst']);
- Res := FSourcePlugin.FVFSListFirst(FGlobs, PChar(APath), P);
+ if @FSourcePlugin.FVFSListFirst = nil then begin
+ Result := ERRNoAccess;
+ Exit;
+ end;
+ P := real_libc_malloc(sizeof(TVFSItem));
+ memset(P, 0, sizeof(TVFSItem));
+ Res := FSourcePlugin.FVFSListFirst(FGlobs, PChar(APath), P, FollowSymlinks, AddFullPath);
if Res <> cVFS_OK then begin
FSourcePlugin.FVFSListClose(FGlobs);
if Res = cVFS_Not_More_Files then Result := 0
@@ -429,68 +461,17 @@ begin
end;
repeat
-// DebugMsg(['begin--']);
- if AddDotFiles or (not ((Length(P^.FName) > 1) and (P^.FName[0] = '.') and (P^.FName[1] <> '.'))) then begin
-// DebugMsg(['Checkpoint 1']);
- Item := malloc(SizeOf(TDataItem));
- memset(Item, 0, SizeOf(TDataItem));
-// DebugMsg(['Checkpoint 2']);
- for i := 0 to Length(Item^.ColumnData) - 1 do Item^.ColumnData[i] := nil;
-// DebugMsg(['Checkpoint 3']);
- with Item^ do
- try
- FName := strdup(P^.FName);
- FDisplayName := strdup(P^.FDisplayName);
- if P^.sLinkTo <> nil
- then begin
- LnkPointTo := strdup(P^.sLinkTo);
- DebugMsg(['LnkPointTo = ', P^.sLinkTo]);
- end else LnkPointTo := nil;
- Mode := P^.iMode;
-// DebugMsg(['Checkpoint 4']);
- IsDotFile := (Length(FName) > 1) and (FName[0] = '.') and (FName[1] <> '.');
- IsDir := TVFSItemType(P^.ItemType) = vDirectory;
- IsLnk := TVFSItemType(P^.ItemType) = vSymlink;
- IsBlk := TVFSItemType(P^.ItemType) = vBlockdev;
- IsChr := TVFSItemType(P^.ItemType) = vChardev;
- IsFIFO := TVFSItemType(P^.ItemType) = vFifo;
- IsSock := TVFSItemType(P^.ItemType) = vSock;
-// DebugMsg(['Checkpoint 5']);
- ModifyTime := P^.m_time;
-// DebugMsg(['Returned datetime: ', Longword(P^.m_time)]);
-// DebugMsg(['Checkpoint 6']);
- UID := P^.iUID;
-// DebugMsg(['Checkpoint 7']);
- GID := P^.iGID;
-// DebugMsg(['Checkpoint 8']);
- UpDir := False;
-// DebugMsg(['Checkpoint 9']);
- Selected := False;
-// DebugMsg(['Checkpoint 10']);
- Size := P^.iSize;
-// DebugMsg(['Checkpoint 11']);
- List.Add(Item);
-// DebugMsg(['Checkpoint 12']);
- except
- on E: Exception do
- DebugMsg(['^^VFS (EE): GetListing: Item-Exception: ', E.Message]);
- end;
- end; // of if AddDotFiles
+ if (strlen(P^.FName) > 0) and (AddDotFiles or (P^.FName[0] <> '.')) then begin
+ Item := GetDataItemFromVFSItem(P);
+ List.Add(Item);
+ end;
if P^.FName <> nil then real_libc_free(P^.FName);
if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
- real_libc_free(P); // Not needed - just zero-erase the memory
-// DebugMsg(['Checkpoint 13']);
- P := real_libc_malloc(SizeOf(TVFSItem));
- memset(P, 0, SizeOf(TVFSItem));
-// DebugMsg(['Item = ', Int64(P)]);
-// DebugMsg(['Checkpoint 14']);
-// DebugMsg(['FVFSListNext --begin']);
- Res := FSourcePlugin.FVFSListNext(FGlobs, PChar(APath), P);
-// DebugMsg(['FVFSListNext --end']);
-// Sleep(500);
- until (Res <> cVFS_OK) or (BreakProcessingKind = 2);
- if BreakProcessingKind <> 0 then DebugMsg(['^^VFS (WW): GetListing: stopped by BreakProcessing']);
+ memset(P, 0, sizeof(TVFSItem));
+ Res := FSourcePlugin.FVFSListNext(FGlobs, P);
+ until (Res <> cVFS_OK) or (BreakProcessingType = 2);
+ if BreakProcessingType <> 0 then DebugMsg(['^^VFS (WW): GetListing: stopped by BreakProcessing']);
real_libc_free(P);
FSourcePlugin.FVFSListClose(FGlobs);
@@ -499,62 +480,67 @@ begin
on E: Exception do
DebugMsg(['^^VFS (EE): GetListing: Exception: ', E.Message]);
end;
- BreakProcessingKind := 0;
+ BreakProcessingType := 0;
DebugMsg(['^^VFS (II): GetListing end.']);
end;
-function TVFSEngine.GetListing(var List: TList; const AddDotFiles: boolean): integer;
-begin
- Result := GetListing(List, AddDotFiles, GetPath);
-end;
-
-function TVFSEngine.ExplicitChDir(const NewPath: string): integer;
-begin
- Result := libc_chdir(PChar(NewPath));
- if Result <> 0 then Result := errno;
-end;
-
-function TVFSEngine.GetFileSystemSize: Int64;
-begin
- Result := GetFileSystemSize(GetPath);
-end;
-
-function TVFSEngine.GetFileSystemSize(const APath: string): Int64;
-begin
- if (FGlobs <> nil) and (@FSourcePlugin.FVFSGetFileSystemSize <> nil)
- then Result := FSourcePlugin.FVFSGetFileSystemSize(FGlobs, PChar(APath))
- else Result := 0;
-end;
-
-function TVFSEngine.GetFileSystemFree: Int64;
-begin
- Result := GetFileSystemFree(GetPath);
-end;
-
-function TVFSEngine.GetFileSystemFree(const APath: string): Int64;
+function TVFSEngine.GetFileInfo(const APath: string; FollowSymlinks, AddFullPath: boolean): PDataItem;
+var P: PVFSItem;
+ Res: integer;
begin
- if (FGlobs <> nil) and (@FSourcePlugin.FVFSGetFileSystemFree <> nil)
- then Result := FSourcePlugin.FVFSGetFileSystemFree(FGlobs, PChar(APath))
- else Result := 0;
+ DebugMsg(['^^VFS (II): GetFileInfo begin']);
+ Result := nil;
+ if @FSourcePlugin.FVFSFileInfo = nil then Exit;
+ try
+ P := real_libc_malloc(sizeof(TVFSItem));
+ memset(P, 0, sizeof(TVFSItem));
+ Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(APath), P, FollowSymlinks, AddFullPath);
+ if Res = cVFS_OK then
+ Result := GetDataItemFromVFSItem(P);
+ if P^.FName <> nil then real_libc_free(P^.FName);
+ if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
+ if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
+ real_libc_free(P);
+ except
+ on E: Exception do
+ DebugMsg(['^^VFS (EE): GetFileInfo: Exception: ', E.Message]);
+ end;
+ DebugMsg(['^^VFS (II): GetFileInfo end.']);
end;
+(********************************************************************************************************************************)
procedure TVFSEngine.GetFileSystemInfo(const APath: string; var FSSize, FSFree: Int64; var FSName: string);
+var AFSSize, AFSFree: Int64;
+ AFSName: PChar;
begin
- FSSize := GetFileSystemSize(APath);
- FSFree := GetFileSystemFree(APath);
+ FSSize := -1;
+ FSFree := -1;
FSName := 'plugin';
+ if @FSourcePlugin.FVFSGetFileSystemInfo <> nil then begin
+ AFSSize := -1;
+ AFSFree := -1;
+ AFSName := nil;
+ if FSourcePlugin.FVFSGetFileSystemInfo(FGlobs, PChar(APath), @AFSSize, @AFSFree, @AFSName) = cVFS_OK then begin
+ FSSize := AFSSize;
+ FSFree := AFSFree;
+ if AFSName <> nil then begin
+ FSName := string(AFSName);
+ real_libc_free(AFSName);
+ end;
+ end;
+ end;
end;
function TVFSEngine.IsOnROMedium(const FileName: string): boolean;
begin
- Result := True;
+ Result := FArchiveMode;
end;
function TVFSEngine.FileCanRun(const FileName: string): boolean;
-var Item: PDataItemSL;
+var Item: PDataItem;
begin
- Item := GetFileInfoSL(FileName);
- Result := Assigned(Item) and Item^.IsExecutable;
+ Item := GetFileInfo(FileName, True, True);
+ Result := (Item <> nil) and Item^.IsExecutable;
FreeDataItem(Item);
end;
@@ -614,81 +600,39 @@ begin
ChangeDir(Value);
end;
-function TVFSEngine.FileExists(const FileName: string; const Use_lstat: boolean = False): Boolean;
-begin
- if (FGlobs <> nil) and (@FSourcePlugin.FVFSFileExists <> nil)
- then Result := FSourcePlugin.FVFSFileExists(FGlobs, PChar(FileName), Use_lstat)
- else Result := False;
-end;
-
-function TVFSEngine.DirectoryExists(const FileName: string; const Use_lstat: boolean = False): Boolean;
+function TVFSEngine.FileExists(const FileName: string; FollowSymlinks: boolean): boolean;
var P: PVFSItem;
- Res: integer;
begin
- if @FSourcePlugin.FVFSFileExists <> nil then begin
- Result := FSourcePlugin.FVFSFileExists(FGlobs, PChar(FileName), Use_lstat);
- if Result and (@FSourcePlugin.FVFSFileInfo <> nil) then begin
- P := real_libc_malloc(SizeOf(TVFSItem));
- memset(P, 0, SizeOf(TVFSItem));
- Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(FileName), P);
- if (Res <> cVFS_OK) or (P = nil) or (TVFSItemType(P^.ItemType) <> vDirectory) then Result := False;
- real_libc_free(P);
- end;
- end else Result := False;
+ Result := False;
+ if (FGlobs = nil) or (@FSourcePlugin.FVFSFileInfo = nil) then
+ Exit;
+ try
+ P := real_libc_malloc(sizeof(TVFSItem));
+ memset(P, 0, sizeof(TVFSItem));
+ Result := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(FileName), P, FollowSymlinks, False) = cVFS_OK;
+ real_libc_free(P);
+ except
+ on E: Exception do
+ DebugMsg(['^^VFS (EE): FileExists: Exception: ', E.Message]);
+ end;
end;
-function TVFSEngine.GetFileInfoSL(APath: string): PDataItemSL;
+function TVFSEngine.DirectoryExists(const FileName: string; FollowSymlinks: boolean): boolean;
var P: PVFSItem;
- Item: PDataItemSL;
Res: integer;
begin
- Result := nil;
- if @FSourcePlugin.FVFSFileInfo = nil then Exit;
- P := real_libc_malloc(SizeOf(TVFSItem));
- memset(P, 0, SizeOf(TVFSItem));
-
- Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(APath), P);
- if Res <> cVFS_OK then begin
- DebugMsg(['*** VFSFileInfo(', APath, ') failed. Code = ', Res]);
+ Result := False;
+ if (FGlobs = nil) or (@FSourcePlugin.FVFSFileInfo = nil) then
Exit;
- end;
-
try
- Item := malloc(SizeOf(TDataItemSL));
- memset(Item, 0, SizeOf(TDataItemSL));
- with Item^ do begin
-{ FName := strdup(P^.FName);
- FDisplayName := StrToUTF8(P^.FName); }
- FName := strdup(PChar(APath));
-
- //* TODO
- FDisplayName := StrToUTF8(PChar(APath));
- if P^.sLinkTo <> nil then LnkPointTo := strdup(P^.sLinkTo)
- else LnkPointTo := nil;
- ADestination := nil;
- Stage1 := True;
- Level := 0;
- IsDir := TVFSItemType(P^.ItemType) = vDirectory;
- IsLnk := TVFSItemType(P^.ItemType) = vSymlink;
- ForceMove := False;
-{***} IsOnRO := True;
- IsExecutable := P^.iMode and S_IXUSR = S_IXUSR;
- Mode := P^.iMode;
- ModifyTime := P^.m_time;
- mtime := P^.m_time;
- atime := P^.a_time;
- UID := P^.iUID;
- GID := P^.iGID;
- Size := P^.iSize;
- PackedSize := P^.iPackedSize;
- if P^.FName <> nil then real_libc_free(P^.FName);
- if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
- if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
- real_libc_free(P);
- end;
- Result := Item;
+ P := real_libc_malloc(sizeof(TVFSItem));
+ memset(P, 0, sizeof(TVFSItem));
+ Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(FileName), P, FollowSymlinks, False);
+ Result := (Res = cVFS_OK) and (TVFSItemType(P^.ItemType) = vDirectory);
+ real_libc_free(P);
except
- on E: Exception do DebugMsg(['*** TVFSEngine.GetFileInfoSL(APath=', APath, ') -Exception: ', E.Message]);
+ on E: Exception do
+ DebugMsg(['^^VFS (EE): FileExists: Exception: ', E.Message]);
end;
end;
@@ -698,165 +642,43 @@ begin
else Result := cVFS_Failed;
end;
-function TVFSEngine.Remove(APath: string): integer;
+function TVFSEngine.Remove(const APath: string): integer;
begin
if @FSourcePlugin.FVFSRemove <> nil then Result := FSourcePlugin.FVFSRemove(FGlobs, PChar(APath))
else Result := cVFS_Failed;
end;
-function TVFSEngine.RenameFile(SourceFile, DestFile: string): integer;
+function TVFSEngine.RenameFile(const SourceFile, DestFile: string): integer;
begin
if @FSourcePlugin.FVFSRename <> nil then Result := FSourcePlugin.FVFSRename(FGlobs, PChar(SourceFile), PChar(DestFile))
else Result := cVFS_Failed;
end;
-procedure TVFSEngine.FillDirFiles(APath: string; List: TList; ALevel: word);
-var Item: PDataItemSL;
- i, Res: integer;
- FilesList: TList;
- LocalList: TStringList;
- P: PVFSItem;
-
-
- procedure AddEntry(FPath: string; AddCurrDirStage, AStage1: boolean);
- begin
- Item := malloc(SizeOf(TDataItemSL));
- memset(Item, 0, SizeOf(TDataItemSL));
- with Item^ do begin
-// AName := malloc(Length(FPath) + 1);
-// memset(AName, 0, Length(FPath) + 1);
- FName := strdup(PChar(FPath));
-
- //* TODO
- FDisplayName := StrToUTF8(PChar(FPath));
- if P^.sLinkTo <> nil then LnkPointTo := strdup(P^.sLinkTo)
- else LnkPointTo := nil;
- ADestination := nil;
- Stage1 := AStage1;
- IsDir := TVFSItemType(P^.ItemType) = vDirectory;
- IsLnk := TVFSItemType(P^.ItemType) = vSymlink;
- if IsLnk and AddCurrDirStage then DebugMsg(['*** Assertion failed AddEntry: Item^.IsLnk = True']);
- ForceMove := False;
-{***} IsOnRO := True;
- IsExecutable := AddCurrDirStage or (P^.iMode and S_IXUSR = S_IXUSR);
- Mode := P^.iMode;
- ModifyTime := P^.m_time;
- mtime := P^.m_time;
- atime := P^.a_time;
- UID := P^.iUID;
- GID := P^.iGID;
- Size := P^.iSize;
- PackedSize := P^.iPackedSize;
- Level := ALevel + Ord(not AddCurrDirStage);
- end;
- if AddCurrDirStage then List.Add(Item)
- else FilesList.Add(Item);
- end;
-
-begin
- if not Assigned(List) then Exit;
- FilesList := TList.Create;
- LocalList := TStringList.Create;
- try
- try
- P := real_libc_malloc(SizeOf(TVFSItem));
- memset(P, 0, SizeOf(TVFSItem));
- Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(APath), P);
- if Res <> cVFS_OK then DebugMsg(['*** FillDirFiles - VFSFileInfo(', APath, ') failed. Code = ', Res]);
- AddEntry(APath, True, True);
- if P^.FName <> nil then real_libc_free(P^.FName);
- if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
- if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
- real_libc_free(P);
-
- APath := IncludeTrailingPathDelimiter(APath);
- if @FSourcePlugin.FVFSChangeDir <> nil then Res := FSourcePlugin.FVFSChangeDir(FGlobs, PChar(APath))
- else Exit;
- if Res <> 0 then Exit;
-
- if @FSourcePlugin.FVFSListFirst = nil then Exit;
- P := real_libc_malloc(SizeOf(TVFSItem));
- memset(P, 0, SizeOf(TVFSItem));
- Res := FSourcePlugin.FVFSListFirst(FGlobs, PChar(APath), P);
- if Res <> cVFS_OK then begin
- FSourcePlugin.FVFSListClose(FGlobs);
- if P^.FName <> nil then real_libc_free(P^.FName);
- if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
- if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
- real_libc_free(P);
- Exit;
- end;
-
- repeat
- if TVFSItemType(P^.ItemType) = vDirectory
- then LocalList.Add(APath + String(P^.FName))
- else AddEntry(APath + String(P^.FName), False, True);
- if P^.FName <> nil then real_libc_free(P^.FName);
- if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
- if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
- real_libc_free(P);
- P := real_libc_malloc(SizeOf(TVFSItem));
- memset(P, 0, SizeOf(TVFSItem));
- Res := FSourcePlugin.FVFSListNext(FGlobs, PChar(GetPath), P);
- until (Res <> cVFS_OK);
-
- if P^.FName <> nil then real_libc_free(P^.FName);
- if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
- if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
- real_libc_free(P);
- FSourcePlugin.FVFSListClose(FGlobs);
-
- if LocalList.Count > 0 then
- for i := 0 to LocalList.Count - 1 do
- FillDirFiles(LocalList[i], List, ALevel + 1);
-
- if FilesList.Count > 0 then
- for i := 0 to FilesList.Count - 1 do
- List.Add(FilesList[i]);
- except
- on E: Exception do DebugMsg(['*** TVFSEngine.FillDirFiles(APath=', APath, ', Level=', ALevel, ') -Exception: ', E.Message]);
- end;
- finally
- P := real_libc_malloc(SizeOf(TVFSItem));
- memset(P, 0, SizeOf(TVFSItem));
- Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(APath), P);
- if Res <> cVFS_OK then DebugMsg(['*** FillDirFiles - VFSFileInfo(', APath, ') failed. Code = ', Res]);
- AddEntry(APath, True, False);
- if P^.FName <> nil then real_libc_free(P^.FName);
- if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
- if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
- real_libc_free(P);
-
- LocalList.Free;
- FilesList.Free;
- end;
-end;
-
function TVFSEngine.MakeSymLink(const NewFileName, PointTo: string): integer;
begin
if @FSourcePlugin.FVFSMakeSymLink <> nil then Result := FSourcePlugin.FVFSMakeSymLink(FGlobs, PChar(NewFileName), PChar(PointTo))
else Result := cVFS_Failed;
end;
-function TVFSEngine.Chmod(const FileName: string; const Mode: integer): integer;
+function TVFSEngine.Chmod(const FileName: string; Mode: cuLong): integer;
begin
if @FSourcePlugin.FVFSChmod <> nil then Result := FSourcePlugin.FVFSChmod(FGlobs, PChar(FileName), Mode)
else Result := cVFS_Failed;
end;
-function TVFSEngine.Chown(const FileName: string; const UID, GID: integer): integer;
+function TVFSEngine.Chown(const FileName: string; UID, GID: cuLong): integer;
begin
if @FSourcePlugin.FVFSChown <> nil then Result := FSourcePlugin.FVFSChown(FGlobs, PChar(FileName), UID, GID)
else Result := cVFS_Failed;
end;
-function TVFSEngine.ChangeTimes(APath: string; mtime, atime: Int64): integer;
+function TVFSEngine.ChangeTimes(const APath: string; mtime, atime: time_t): integer;
begin
if @FSourcePlugin.FVFSChangeTimes <> nil then Result := FSourcePlugin.FVFSChangeTimes(FGlobs, PChar(APath), mtime, atime)
else Result := cVFS_Failed;
end;
-function TVFSEngine.GetDirSize(APath: string): Int64;
+function TVFSEngine.GetDirSize(const APath: string): Int64;
begin
if @FSourcePlugin.FVFSGetDirSize <> nil then Result := FSourcePlugin.FVFSGetDirSize(FGlobs, PChar(APath))
else Result := 0;
@@ -883,10 +705,11 @@ end;
(********************************************************************************************************************************)
-function TVFSEngine.IsOnSameFS(const Path1, Path2: string): boolean;
+function TVFSEngine.IsOnSameFS(const Path1, Path2: string; FollowSymlinks: boolean): boolean;
begin
- if @FSourcePlugin.FVFSIsOnSameFS <> nil then Result := FSourcePlugin.FVFSIsOnSameFS(FGlobs, PChar(Path1), PChar(Path2))
- else Result := True;
+ if @FSourcePlugin.FVFSIsOnSameFS <> nil
+ then Result := FSourcePlugin.FVFSIsOnSameFS(FGlobs, PChar(Path1), PChar(Path2), FollowSymlinks)
+ else Result := True;
end;
function TVFSEngine.OpenFile(const APath: string; Mode: integer; var Error: integer): TEngineFileDes;
@@ -931,26 +754,26 @@ begin
end else Result := -1;
end;
-function TVFSEngine.TwoSameFiles(const Path1, Path2: string): boolean;
+function TVFSEngine.TwoSameFiles(const Path1, Path2: string; FollowSymlinks: boolean): boolean;
begin
- if @FSourcePlugin.FVFSTwoSameFiles <> nil then Result := FSourcePlugin.FVFSTwoSameFiles(FGlobs, PChar(Path1), PChar(Path2))
+ if @FSourcePlugin.FVFSTwoSameFiles <> nil then Result := FSourcePlugin.FVFSTwoSameFiles(FGlobs, PChar(Path1), PChar(Path2), FollowSymlinks)
else Result := False;
end;
(********************************************************************************************************************************)
-function TVFSEngine.CopyFileIn(Sender: Pointer; SourceFile, DestFile: string; ProgressFunc: TEngineProgressFunc; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean;
+function TVFSEngine.CopyFileIn(Sender: Pointer; const SourceFile, DestFile: string; ProgressFunc: TEngineProgressFunc; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean;
begin
Result := CopyFileInEx(Sender, SourceFile, DestFile, ErrorFunc, Append, nil, nil, nil, nil);
end;
-function TVFSEngine.CopyFileOut(Sender: Pointer; SourceFile, DestFile: string; ProgressFunc: TEngineProgressFunc; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean;
+function TVFSEngine.CopyFileOut(Sender: Pointer; const SourceFile, DestFile: string; ProgressFunc: TEngineProgressFunc; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean;
begin
Result := CopyFileInEx(Sender, SourceFile, DestFile, ErrorFunc, Append, nil, nil, nil, nil);
end;
-function TVFSEngine.CopyFileOutEx(Sender: Pointer; SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc; Append: boolean;
+function TVFSEngine.CopyFileOutEx(Sender: Pointer; const SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc; Append: boolean;
AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
var Res: TVFSResult;
begin
@@ -986,7 +809,7 @@ begin
end;
end;
-function TVFSEngine.CopyFileInEx(Sender: Pointer; SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc;
+function TVFSEngine.CopyFileInEx(Sender: Pointer; const SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc;
Append: boolean; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
var Res: TVFSResult;
begin