EldoS | Feel safer!

Software components for data protection, secure storage and transfer

[TElZipWriter] bug with add method ?

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
#24282
Posted: 03/25/2013 09:40:43
by Damien Griessinger (Standard support level)
Joined: 03/14/2013
Posts: 9

I continue to adapt my project for using TElZipWriter and I have found something strange.
To try to debug I have made very small example:
Code
program Project1;

{$APPTYPE CONSOLE}

uses
  Windows,
  Classes,
  SysUtils,
  SBUtils,
  SBArcBase,
  SBArcZip,
  SBZipUtils;

var fzip:TElZipWriter;
    inStream:TStringStream;
begin
fzip:=TElZipWriter.create(nil);
fzip.Open('a.zip',false); // Note that a.zip file already exists.
fzip.ReplaceMode:=armAlways;
inStream:=TStringStream.Create;
inStream.WriteString('TEST DATA');
inStream.Position:=0;
fzip.Add(inStream,'toto.txt');
fzip.Compress();
inStream.Free;
fzip.Close;
fzip.Free;
end.



I run once, open the zip, and I see toto.txt: OK
I run another time; open the zip and I see 2 files called toto.txt : KO !!!

fzip.ReplaceMode:=armAlways; // not working ?

The version used is 10.0.233.
Thanks a lot for your help
#24284
Posted: 03/25/2013 09:58:21
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

Hi. This is not a bug - ReplaceMode is used only when files added via pathes in file system.
If you are adding files as streams you should check if this file already exists in archive, and decide what to do.
#24289
Posted: 03/25/2013 11:39:12
by Damien Griessinger (Standard support level)
Joined: 03/14/2013
Posts: 9

Ok, I understand,

I have add

Code
entry := fzip.Directory.EntryWithName(filename);
if (entry <> nil) and (not entry.IsDirectory) then fzip.Remove(filename);

and it's working perfect when file is on root.

But I get trouble using file outside the root (filename:='aaaa/bbbb/toto.txt), I have try to found a solution but I'm sure that is not the good way how to do:

Code
  filename:='aaaa/bbbb/toto.txt';
  fdir:=ExtractDirectory(filename);
  fname:=ExtractFile(filename);

  if fdir='' then
    entry := fzip.Directory.EntryWithPath(fname)
  else
  begin
    entry := fzip.Directory.EntryWithPath(fdir);
    if (entry<>nil) then
     entry:=entry.EntryWithName(fname);
  end;


if (entry <> nil) and (not entry.IsDirectory) then
  fzip.Remove(filename);

fzip.Add(inStream,filename);
fzip.Compress();
#24293
Posted: 03/25/2013 13:04:03
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

Actually, you can use fzip.Directory.EntryWithPath(filename). This function works with the full path inside of archive.

Reply

Statistics

Topic viewed 502 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!