FIX: Opening archives on file sources with links to local files.

This commit is contained in:
cobines 2010-04-24 22:17:59 +00:00
commit 88f030eabf
3 changed files with 54 additions and 31 deletions

View file

@ -16,30 +16,28 @@ type
IArchiveFileSource = interface(ILocalFileSource)
['{13A8637C-FFDF-46B0-B5B4-E7C6851C157A}']
function GetArchiveFileSource: IFileSource;
{en
Full path to the archive on the ArchiveFileSource.
Full path to the archive on the ParentFileSource.
}
property ArchiveFileName: String read GetCurrentAddress;
{en
File source that has the archive on it.
It should be direct-access file source (usually filesystem).
}
property ArchiveFileSource: IFileSource read GetArchiveFileSource;
end;
TArchiveFileSource = class(TLocalFileSource, IArchiveFileSource)
private
FArchiveFileSource: IFileSource; //en> File source that has the archive.
protected
function GetSupportedFileProperties: TFilePropertiesTypes; override;
function GetArchiveFileSource: IFileSource;
public
{en
Creates an archive file source.
@param(anArchiveFileSource
File source that stores the archive.
Usually it will be direct-access file source, like filesystem.)
@param(anArchiveFileName
Full path to the archive on the ArchiveFileSource.)
}
constructor Create(anArchiveFileSource: IFileSource;
anArchiveFileName: String); virtual reintroduce overload;
@ -54,8 +52,8 @@ constructor TArchiveFileSource.Create(anArchiveFileSource: IFileSource;
anArchiveFileName: String);
begin
FCurrentAddress := anArchiveFileName;
FArchiveFileSource := anArchiveFileSource;
inherited Create;
ParentFileSource := anArchiveFileSource;
end;
class function TArchiveFileSource.CreateFile(const APath: String): TFile;
@ -77,10 +75,5 @@ begin
+ [fpSize, fpCompressedSize, fpAttributes, fpModificationTime];
end;
function TArchiveFileSource.GetArchiveFileSource: IFileSource;
begin
Result := FArchiveFileSource;
end;
end.

View file

@ -83,16 +83,28 @@ begin
if fspDirectAccess in SourceFileSource.Properties then
begin
Result := GetArchiveFileSourceDirect(SourceFileSource, ArchiveFile.FullPath, ArchiveType, ArchiveSign);
end
else if fspLinksToLocalFiles in SourceFileSource.Properties then
begin
SourceFileSource.GetLocalName(ArchiveFile);
Result := GetArchiveFileSourceDirect(SourceFileSource, ArchiveFile.FullPath, ArchiveType, ArchiveSign);
end
else if fsoCopyOut in SourceFileSource.GetOperationsTypes then
begin
Result := nil;
Exit;
end;
Result := nil;
if fspLinksToLocalFiles in SourceFileSource.Properties then
begin
if SourceFileSource.GetLocalName(ArchiveFile) then
begin
TempFS := TTempFileSystemFileSource.Create(ArchiveFile.Path);
// Source FileSource manages the files, not the TempFileSource.
TempFS.DeleteOnDestroy := False;
// The files on temp file source are valid as long as source FileSource is valid.
TempFS.ParentFileSource := SourceFileSource;
Result := GetArchiveFileSourceDirect(TempFS, ArchiveFile.FullPath, ArchiveType, ArchiveSign);
// If not successful will try to get files through CopyOut below.
end;
end;
if (not Assigned(Result)) and
(fsoCopyOut in SourceFileSource.GetOperationsTypes) then
begin
if (ArchiveType = EmptyStr) and (ArchiveSign = False) then
begin
ArchiveType := ArchiveFile.Extension;
@ -139,10 +151,6 @@ begin
if Assigned(Operation) then
FreeAndNil(Operation);
end;
end
else
begin
Result := nil;
end;
end;

View file

@ -39,6 +39,8 @@ type
function GetOperationsTypes: TFileSourceOperationTypes;
function GetProperties: TFileSourceProperties;
function GetFiles(TargetPath: String): TFiles;
function GetParentFileSource: IFileSource;
procedure SetParentFileSource(NewValue: IFileSource);
function CreateFileObject(const APath: String): TFile;
@ -82,6 +84,7 @@ type
procedure RemoveReloadEventListener(FunctionToCall: TFileSourceReloadEventNotify);
property CurrentAddress: String read GetCurrentAddress;
property ParentFileSource: IFileSource read GetParentFileSource write SetParentFileSource;
property Properties: TFileSourceProperties read GetProperties;
property SupportedFileProperties: TFilePropertiesTypes read GetSupportedFileProperties;
end;
@ -92,6 +95,11 @@ type
private
FReloadEventListeners: TMethodList;
{en
File source on which this file source is dependent on
(files that it accesses are on the parent file source).
}
FParentFileSource: IFileSource;
{en
Callback called when an operation assigned to a connection finishes.
@ -129,6 +137,9 @@ type
}
function GetSupportedFileProperties: TFilePropertiesTypes; virtual;
function GetParentFileSource: IFileSource;
procedure SetParentFileSource(NewValue: IFileSource);
{en
Checks if the connection is available and, if it is, assigns it to the operation.
@returns(Connection object if the connection is available,
@ -230,6 +241,7 @@ type
procedure RemoveReloadEventListener(FunctionToCall: TFileSourceReloadEventNotify);
property CurrentAddress: String read GetCurrentAddress;
property ParentFileSource: IFileSource read GetParentFileSource write SetParentFileSource;
property Properties: TFileSourceProperties read GetProperties;
property SupportedFileProperties: TFilePropertiesTypes read GetSupportedFileProperties;
@ -406,6 +418,16 @@ begin
Result := [fpName];
end;
function TFileSource.GetParentFileSource: IFileSource;
begin
Result := FParentFileSource;
end;
procedure TFileSource.SetParentFileSource(NewValue: IFileSource);
begin
FParentFileSource := NewValue;
end;
function TFileSource.IsPathAtRoot(Path: String): Boolean;
begin
Result := (Path = GetRootDir(Path));