unzipping a file gives no error when harddisk is full
Original Reporter info from Mantis: valdir.marcos @valdir.marcos
-
Reporter name: Valdir Marcos
Original Reporter info from Mantis: valdir.marcos @valdir.marcos
- Reporter name: Valdir Marcos
Description:
"When I unzip a file, which is bigger than the free space on the destination harddisk, I get no error.
The file is just truncated.
I would expect to get an error, because the file is invalid."
Please, see this forum discussion:
unzipping a file gives no error when harddisk is full
https://forum.lazarus.freepascal.org/index.php/topic,46711.msg333448.html#msg333448
Steps to reproduce:
{$mode objfpc}{$H+}
uses classes,sysutils,zipper;
function unzip_file(fspecZ,fspecP,destDir: ansistring): ansistring;
{unzips packed file 'fspecP' from zipfile 'fspecZ' to destination 'destDir'}0
var
Z: TUnZipper;
SL: TStringList;
begin
Z:=TUnZipper.Create;
SL:=TStringList.Create;
try
SL.Add(fspecP);
Z.FileName:=fspecZ;
Z.OutputPath:=destDir;
Z.UnZipFiles(SL);
Z.Free;
SL.Free;
exit(''); {if no Error}
except
on E: EZipError do
begin
Z.Free; SL.Free; exit('Error 1 ' + E.Message);
end;
on E: Exception do {all other Exceptions: }
begin
Z.Free; SL.Free; exit('Error 2 ' + E.Message);
end;
end;
end;
var
fspecZ,fspecP,destDir,se: ansistring;
begin
fspecZ:='h:\tmp\Dylan.zip';
fspecP:='Dylan.wav'; // this file is 147 MB big
destDir:='d:\Tst\unzip\'; // this drive has only 137 MB free
se:=unzip_file(fspecZ,fspecP,destDir);
writeln('result="', se, '"');
end.
Additional information:
Alternative solution:
procedure TForm1.Button1Click(Sender: TObject);
var
Z: TUnZipper;
i: Integer;
TotalSize: Int64;
EntrySize: Int64;
FreeSpace: Int64;
begin
z := TUnZipper.Create;
z.FileName := 'h:\tmp\Dylan.zip';
z.OutputPath := 'd:\Tst\unzip\';
z.Examine; // needed!!!
{ ** Total size of all files in the archive ** }
TotalSize := 0;
for i := 0 to z.Entries.Count - 1 do
begin
Inc(TotalSize, z.Entries.Entries[i].Size);
end;
ShowMessage('The size of archive is: ' + IntToStr(TotalSize) + ' bytes.');
{ ** }
{ ** Size of an entry in the archive ** }
EntrySize := 0;
for i := 0 to z.Entries.Count - 1 do
begin
if z.Entries[i].ArchiveFileName = 'Dylan.wav' then
begin
EntrySize := z.Entries[i].Size;
end;
end;
ShowMessage('The size of entry is: ' + IntToStr(EntrySize) + ' bytes.');
{ ** }
{ ** how much free space is there? ** }
FreeSpace := DiskFree(Ord('d') - 64); // "d" is the drive letter
ShowMessage('There are : ' + IntToStr(FreeSpace) + ' bytes free.');
{ ** }
if FreeSpace > EntrySize then // or TotalSize
begin
// do unzip here
end
else
begin
// error message
end;
z.Free;
end;
Mantis conversion info:
- Mantis ID: 36068
- OS: Windows
- OS Build: 10
- Platform: 32 and 64 bits
- Version: 3.0.4
- Fixed in version: 3.3.1
- Fixed in revision: 42975 (#a6a39d2c)
- Target version: 3.2.0