rejetto forum
Software => HFS ~ HTTP File Server => Topic started by: Mars on February 20, 2009, 12:51:19 AM
-
I was going to forget the cherry on the cake... :D
A template way rejetto but which include the possibility of choosing items to be included in an archives tar, provided that the current file is archivable
.......
end;
end; // serveTar
{begin Add by mars 14-fev-08}
procedure archiveperms(); //Add by mars 14-fev-08
var
i,j: integer;
s: string;
listing: TfileListing;
ofs: integer;
tar: TtarStream;
fi: Tfile;
fIsTemp: boolean;
begin
if (conn.request.method <> HM_POST)
or (data.postVars.values['action'] <> 'archive')
then exit;
data.downloadingWhat:=DW_ARCHIVE;
data.countAsDownload:=TRUE;
if limitsExceededOnDownload() then exit;
listing:=TfileListing.create();
try
tar:=TtarStream.create(); // this is freed by ThttpSrv
{deb equiv listing fromfolder}
for i:=0 to data.postvars.count-1 do
if sameText('selection', data.postvars.names) then
begin
s:= decodeURL(getTill('#',data.postvars.valueFromIndex)); // omit #anchors
if ansiEndsStr('/', s) then setLength(s, length(s)-1); // folders' url
s:=substr(s, 1+lastDelimiter('/\',s)); // omit path information
if anycharIn('\/', s) then continue;
s:=f.URL()+s;
s:=decodeURL(f.URL(true)+s); //decodeURL necessary to replace %20 into foldername who contains some spaces
if fi=NIL then continue;
j:=length(listing.dir);
if fi.isfolder then
begin
if fi.hasRecursive(FA_ARCHIVABLE) then
listing.fromFolder( fi, conn, true,-1,-1,false);
end
else
begin
setlength(listing.dir,j+1);
listing.dir[ j ]:=fi;
end;
end;
{end equiv listing fromfolder}
fIsTemp:=f.isTemp();
ofs:=length(f.resource)-length(f.name)+1;
if length(listing.dir)=0 then
begin
getpage('no file',data);
exit;
end;
for i:=0 to length(listing.dir)-1 do
begin
fi:=listing.dir[ i ];
if conn.state = HCS_DISCONNECTED then break
else if fi.isFile() then
if not fIsTemp then
tar.addFile(fi.resource, fi.pathTill(f), if_(not fi.isTemp(), fi))
else // pathTill won't work this case, because f.parent is an ancestor but not the parent
tar.addFile(fi.resource, copy(fi.resource, ofs, MAXINT));
end;
except
getpage('no file',data);
exit;
end;
listing.free;
data.fileXferStart:=now();
conn.reply.mode:=HRM_REPLY;
conn.reply.contentType:='application/x-tar';
conn.reply.bodyMode:=RBM_STREAM;
conn.reply.bodyStream:=tar;
if f.name > '' then
begin
data.lastFN:=if_(f.name='/', 'home', f.name)+'.selection.tar';
conn.addHeader('Content-Disposition: filename="'+data.lastFN+'";');
end;
end; //archiveperms
{end by mars}
procedure checkCurrentAddress();
begin
if limitsExceededOnConnection() then
......
......
if not isAllowedReferer()
or f.isFile() and (FA_DL_FORBIDDEN in f.flags) then
begin
getPage('deny', data);
exit;
end;
{///add by mars 14-fev-08} if f.isFolder and (data.postvars.values['action'] = 'archive') then
begin
archiveperms();
exit;
end;
if urlCmd = '~folder.tar' then
begin
serveTar();
exit;
end;
work at present on the French build 224
Exceptionally is also a link to one version of hfs functional for my two posts last ones which include the new template as default
http://hfs.webhop.org/hfs224_mars.zip
-
thank you mars, but i decided to organize the code differently, and centralize the job in serveTar() since the case of a folder must be hanlded exactly the same way as it was already done.
every case should be handled, so i created this (attached) VFS to test if my code was working good.
additionally: inside the real folder there's a file "4", and another file "t\5" (under "t").
so the point is that you, by entering folder A, should be able to select all (or any) items and get an archive that will reflect the VFS and your selection.
make this test and see if your code is working correctly.
mine is doing.
and if you get to create an example to show a problem with mine, please let me know.