XRootD
Loading...
Searching...
No Matches
XrdClZipListHandler.cc
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN)
3// Author: Michal Simon <michal.simon@cern.ch>
4//------------------------------------------------------------------------------
5// This file is part of the XRootD software suite.
6//
7// XRootD is free software: you can redistribute it and/or modify
8// it under the terms of the GNU Lesser General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// XRootD is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU Lesser General Public License
18// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19//
20// In applying this licence, CERN does not waive the privileges and immunities
21// granted to it by virtue of its status as an Intergovernmental Organization
22// or submit itself to any jurisdiction.
23//------------------------------------------------------------------------------
24
26
27namespace XrdCl
28{
29
31 XrdCl::AnyObject *responseptr )
32 {
33 std::unique_ptr<XRootDStatus> status( statusptr );
34 std::unique_ptr<AnyObject> response( responseptr );
35
36 if( pStep == DONE )
37 {
38 delete this;
39 return;
40 }
41
42 if( !status->IsOK() )
43 {
44 pHandler->HandleResponse( status.release(), response.release() );
45 delete this;
46 return;
47 }
48
49 time_t took = time( 0 ) - pStartTime;
50 if( took > pTimeout )
51 {
53 pHandler->HandleResponse( status.release(), 0 );
54 if( pZip.IsOpen() && DoZipClose( 1, DONE ) )
55 return;
56 delete this;
57 return;
58 }
59 time_t left = pTimeout - took;
60
61 switch( pStep )
62 {
63 case STAT:
64 {
65 StatInfo *info = 0;
66 response->Get( info );
67
68 if( info->TestFlags( StatInfo::IsDir ) )
69 DoDirList( left );
70 else if( DoZipOpen( left ) )
71 return;
72
73 break;
74 }
75
76 case OPEN:
77 {
78 DirectoryList *list = 0;
79 XRootDStatus st = pZip.List( list );
80 if( !st.IsOK() )
81 {
82 pHandler->HandleResponse( new XRootDStatus( st ), 0 );
83 pStep = DONE;
84 }
85 else
86 {
87 pDirList.reset( list );
88 if( DoZipClose( left ) )
89 return;
90 }
91 break;
92 }
93
94 case CLOSE:
95 {
96 AnyObject *resp = new AnyObject();
97 resp->Set( pDirList.release() );
98 pHandler->HandleResponse( new XRootDStatus(), resp );
99 pStep = DONE;
100 break;
101 }
102 }
103
104 if( pStep == DONE )
105 delete this;
106 }
107
108 void ZipListHandler::DoDirList( time_t timeLeft )
109 {
110 FileSystem fs( pUrl );
111 // remove the Zip flag so we don't enter an infinite loop
112 pFlags &= ~DirListFlags::Zip;
113 XRootDStatus st = fs.DirList( pUrl.GetPath(), pFlags, pHandler , timeLeft );
114 pStep = DONE; // no matter whether it works or not, either way we are done
115 if( !st.IsOK() )
116 pHandler->HandleResponse( new XRootDStatus( st ), 0 );
117 }
118
119 //----------------------------------------------------------------------------
120 // The step is set before the call, as the response can come in another
121 // thread before the call returns, and can delete this object.
122 //----------------------------------------------------------------------------
123 bool ZipListHandler::DoZipOpen( time_t timeLeft )
124 {
125 pStep = OPEN;
126 XRootDStatus st = pZip.OpenArchive( pUrl.GetURL(), OpenFlags::Read, this, timeLeft );
127 if( st.IsOK() )
128 return true;
129
130 pHandler->HandleResponse( new XRootDStatus( st ), 0 );
131 pStep = DONE;
132 return false;
133 }
134
135 bool ZipListHandler::DoZipClose( time_t timeLeft, int next )
136 {
137 pStep = next;
138 XRootDStatus st = pZip.CloseArchive( this, timeLeft );
139 if( st.IsOK() )
140 return true;
141
142 if( next != DONE )
143 pHandler->HandleResponse( new XRootDStatus( st ), 0 );
144 pStep = DONE;
145 return false;
146 }
147
148} /* namespace XrdCl */
void Set(Type object, bool own=true)
AnyObject()
Constructor.
Send file/filesystem queries to an XRootD cluster.
virtual void HandleResponse(XRootDStatus *status, AnyObject *response)
Object stat info.
bool TestFlags(uint32_t flags) const
Test flags.
@ IsDir
This is a directory.
const std::string & GetPath() const
Get the path.
Definition XrdClURL.hh:217
std::string GetURL() const
Get the URL.
Definition XrdClURL.hh:86
XRootDStatus(uint16_t st=0, uint16_t code=0, uint32_t errN=0, const std::string &message="")
Constructor.
XRootDStatus OpenArchive(const std::string &url, OpenFlags::Flags flags, ResponseHandler *handler, time_t timeout=0)
virtual void HandleResponse(XrdCl::XRootDStatus *statusptr, XrdCl::AnyObject *responseptr)
Handle the server response.
const uint16_t errOperationExpired
const uint16_t stError
An error occurred that could potentially be retried.
@ Read
Open only for reading.
bool IsOK() const
We're fine.