XRootD
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 
25 #include "XrdClZipListHandler.hh"
26 
27 namespace 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() )
55  {
56  DoZipClose( 1 );
57  pStep = DONE;
58  }
59  else
60  delete this;
61  return;
62  }
63  uint16_t left = pTimeout - took;
64 
65  switch( pStep )
66  {
67  case STAT:
68  {
69  StatInfo *info = 0;
70  response->Get( info );
71 
72  if( info->TestFlags( StatInfo::IsDir ) )
73  DoDirList( left );
74  else
75  DoZipOpen( left );
76 
77  break;
78  }
79 
80  case OPEN:
81  {
82  DirectoryList *list = 0;
83  XRootDStatus st = pZip.List( list );
84  if( !st.IsOK() )
85  {
86  pHandler->HandleResponse( new XRootDStatus( st ), 0 );
87  pStep = DONE;
88  }
89  else
90  {
91  pDirList.reset( list );
92  DoZipClose( left );
93  }
94  break;
95  }
96 
97  case CLOSE:
98  {
99  AnyObject *resp = new AnyObject();
100  resp->Set( pDirList.release() );
101  pHandler->HandleResponse( new XRootDStatus(), resp );
102  pStep = DONE;
103  break;
104  }
105  }
106 
107  if( pStep == DONE )
108  delete this;
109  }
110 
111  void ZipListHandler::DoDirList( time_t timeLeft )
112  {
113  FileSystem fs( pUrl );
114  // remove the Zip flag so we don't enter an infinite loop
115  pFlags &= ~DirListFlags::Zip;
116  XRootDStatus st = fs.DirList( pUrl.GetPath(), pFlags, pHandler , timeLeft );
117  pStep = DONE; // no matter whether it works or not, either way we are done
118  if( !st.IsOK() )
119  pHandler->HandleResponse( new XRootDStatus( st ), 0 );
120  }
121 
122  void ZipListHandler::DoZipOpen( time_t timeLeft )
123  {
124  XRootDStatus st = pZip.OpenArchive( pUrl.GetURL(), OpenFlags::Read, this, timeLeft );
125  if( !st.IsOK() )
126  {
127  pHandler->HandleResponse( new XRootDStatus( st ), 0 );
128  pStep = DONE;
129  }
130  else
131  pStep = OPEN;
132  }
133 
134  void ZipListHandler::DoZipClose( time_t timeLeft )
135  {
136  XRootDStatus st = pZip.CloseArchive( this, timeLeft );
137  if( !st.IsOK() )
138  {
139  pHandler->HandleResponse( new XRootDStatus( st ), 0 );
140  pStep = DONE;
141  }
142  else
143  pStep = CLOSE;
144  }
145 
146 } /* namespace XrdCl */
void Set(Type object, bool own=true)
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.
std::string GetURL() const
Get the URL.
Definition: XrdClURL.hh:86
const std::string & GetPath() const
Get the path.
Definition: XrdClURL.hh:217
XRootDStatus OpenArchive(const std::string &url, OpenFlags::Flags flags, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus List(DirectoryList *&list)
XRootDStatus CloseArchive(ResponseHandler *handler, uint16_t timeout=0)
Create the central directory at the end of ZIP archive and close it.
virtual void HandleResponse(XrdCl::XRootDStatus *statusptr, XrdCl::AnyObject *responseptr)
Handle the server response.
const uint16_t errOperationExpired
Definition: XrdClStatus.hh:90
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32
@ Read
Open only for reading.
bool IsOK() const
We're fine.
Definition: XrdClStatus.hh:124