[delphizip] Re: How to handle overlong or bad filenames

  • From: "James Turner" <james.d.h.turner@xxxxxxxxxxxx>
  • To: <delphizip@xxxxxxxxxxxxx>
  • Date: Mon, 5 Feb 2007 12:18:26 -0000

When CreateFile fails, ideally, an event should be triggered that could work 
something like this

type TZM_CreateErrorEvent = function(SourceFileName, DestFileName:pChar; 
Code:DWORD):pChar of object;

The Code value would be that returned by GetLastError, thus it could be 
translated into a message for the end-user.

If 0 is returned, the extractor should try again.
If 1 is returned, the extractor should skip the file.
If 2 is returned, the whole extraction should terminate.
If a pChar is returned, the extractor should attempt to save the file to the 
alternate name.

By writing an appropriate event handler, the end-user could thus take 
appropriate action.

If no event handler is assigned, a default action should be provided, this 
could include a dialog.

Other than bad file names, CreateFile might fail due to sharing violations, 
write-protection, etc. This event would cover all such possibilities.

A similar event could handle read/write errors. Alternatively, by adding 
another parameter, a single event could handle Create, Read and Write errors 
(but for read/write errors, the event result would be limited to integers 
0,1,2).

-- James Turner


----- Original Message ----- 
From: "R.Peters" <russellpeters@xxxxxxxxxxx>
To: <delphizip@xxxxxxxxxxxxx>
Sent: Monday, February 05, 2007 9:45 AM
Subject: [delphizip] How to handle overlong or bad filenames


> While checking the extraction code I saw some things that don't work in 
> what
> I would call safe way.
>
> At the moment -
> 1) 'bad' characters are replaced by underscores - I think it would be 
> safer
> to skip such files but then they could not be extracted without renaming
> them first (can be done 'on the fly').
> 2) overlong paths or filenames tend to be truncated or, marginally less 
> bad,
> shortened - these too should be skipped.
>
> If it is decided to skip them then future versions could expand the
> 'skipped' enum values.
>
> I feel it is much safer to not extract a file rather than do so with the
> wrong name.
>
> At need one of the events can be used to rename the file (or give it a new
> path) before extraction.
>
> - Russell Peters
>
>
>
>
>
> -----------
> To unsubscribe from this list, send an empty e-mail
> message to:
>  delphizip-request@xxxxxxxxxxxxx
> and put the word unsubscribe in the subject.
> 

-----------
To unsubscribe from this list, send an empty e-mail 
message to:
  delphizip-request@xxxxxxxxxxxxx 
and put the word unsubscribe in the subject.

Other related posts: