xrootd
Loading...
Searching...
No Matches
XrdClZipOperations.hh
Go to the documentation of this file.
1/*
2 * XrdClZipOperations.hh
3 *
4 * Created on: 26 Nov 2020
5 * Author: simonm
6 */
7
8#ifndef SRC_XRDCL_XRDCLZIPOPERATIONS_HH_
9#define SRC_XRDCL_XRDCLZIPOPERATIONS_HH_
10
14#include "XrdCl/XrdClCtx.hh"
15
16namespace XrdCl
17{
18
19 //----------------------------------------------------------------------------
25 //----------------------------------------------------------------------------
26 template<template<bool> class Derived, bool HasHndl, typename Response, typename ... Arguments>
27 class ZipOperation: public ConcreteOperation<Derived, HasHndl, Response, Arguments...>
28 {
29
30 template<template<bool> class, bool, typename, typename ...> friend class ZipOperation;
31
32 public:
33 //------------------------------------------------------------------------
38 //------------------------------------------------------------------------
39 ZipOperation( Ctx<ZipArchive> zip, Arguments... args): ConcreteOperation<Derived, false, Response, Arguments...>( std::move( args )... ), zip( std::move( zip ) )
40 {
41 }
42
43 //------------------------------------------------------------------------
49 //------------------------------------------------------------------------
50 template<bool from>
52 ConcreteOperation<Derived, HasHndl, Response, Arguments...>( std::move( op ) ), zip( op.zip )
53 {
54
55 }
56
57 //------------------------------------------------------------------------
59 //------------------------------------------------------------------------
60 virtual ~ZipOperation()
61 {
62
63 }
64
65 protected:
66
67 //------------------------------------------------------------------------
69 //------------------------------------------------------------------------
71 };
72
73 //----------------------------------------------------------------------------
75 //----------------------------------------------------------------------------
76 template<bool HasHndl>
79 {
80 public:
81
82 //------------------------------------------------------------------------
84 //------------------------------------------------------------------------
86 Arg<OpenFlags::Flags>>::ZipOperation;
87
88 //------------------------------------------------------------------------
90 //------------------------------------------------------------------------
91 enum { UrlArg, FlagsArg };
92
93 //------------------------------------------------------------------------
95 //------------------------------------------------------------------------
96 std::string ToString()
97 {
98 return "ZipOpen";
99 }
100
101 protected:
102
103 //------------------------------------------------------------------------
109 //------------------------------------------------------------------------
110 XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
111 {
112 std::string &url = std::get<UrlArg>( this->args ).Get();
113 OpenFlags::Flags flags = std::get<FlagsArg>( this->args ).Get();
114 uint16_t timeout = pipelineTimeout < this->timeout ?
115 pipelineTimeout : this->timeout;
116 return this->zip->OpenArchive( url, flags, handler, timeout );
117 }
118 };
119
120 //----------------------------------------------------------------------------
122 //----------------------------------------------------------------------------
124 Arg<OpenFlags::Flags> flags, uint16_t timeout = 0 )
125 {
126 return OpenArchiveImpl<false>( std::move( zip ), std::move( fn ),
127 std::move( flags ) ).Timeout( timeout );
128 }
129
130
131 //----------------------------------------------------------------------------
133 //----------------------------------------------------------------------------
134 template<bool HasHndl>
135 class OpenFileImpl: public ZipOperation<OpenFileImpl, HasHndl, Resp<void>,
136 Arg<std::string>, Arg<OpenFlags::Flags>, Arg<uint64_t>, Arg<uint32_t>>
137 {
138 public:
139
140 //------------------------------------------------------------------------
142 //------------------------------------------------------------------------
145
146 //------------------------------------------------------------------------
148 //------------------------------------------------------------------------
150
151 //------------------------------------------------------------------------
153 //------------------------------------------------------------------------
154 std::string ToString()
155 {
156 return "ZipOpenFile";
157 }
158
159 protected:
160
161 //------------------------------------------------------------------------
167 //------------------------------------------------------------------------
168 XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
169 {
170 std::string &fn = std::get<FnArg>( this->args ).Get();
171 OpenFlags::Flags flags = std::get<FlagsArg>( this->args ).Get();
172 uint64_t size = std::get<SizeArg>( this->args ).Get();
173 uint32_t crc32 = std::get<Crc32Arg>( this->args ).Get();
174 XRootDStatus st = this->zip->OpenFile( fn, flags, size, crc32 );
175 if( !st.IsOK() ) return st;
176 handler->HandleResponse( new XRootDStatus(), nullptr );
177 return XRootDStatus();
178 }
179 };
180
181 //----------------------------------------------------------------------------
183 //----------------------------------------------------------------------------
186 Arg<uint32_t> crc32 = 0, uint16_t timeout = 0 )
187 {
188 return OpenFileImpl<false>( std::move( zip ), std::move( fn ), std::move( flags ),
189 std::move( size ), std::move( crc32 ) ).Timeout( timeout );
190 }
191
192
193 //----------------------------------------------------------------------------
195 //----------------------------------------------------------------------------
196 template<bool HasHndl>
197 class ZipReadImpl: public ZipOperation<ZipReadImpl, HasHndl, Resp<ChunkInfo>,
198 Arg<uint64_t>, Arg<uint32_t>, Arg<void*>>
199 {
200 public:
201
202 //------------------------------------------------------------------------
204 //------------------------------------------------------------------------
207
208 //------------------------------------------------------------------------
210 //------------------------------------------------------------------------
212
213 //------------------------------------------------------------------------
215 //------------------------------------------------------------------------
216 std::string ToString()
217 {
218 return "ZipRead";
219 }
220
221 protected:
222
223 //------------------------------------------------------------------------
229 //------------------------------------------------------------------------
230 XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
231 {
232 uint64_t offset = std::get<OffsetArg>( this->args ).Get();
233 uint32_t size = std::get<SizeArg>( this->args ).Get();
234 void *buffer = std::get<BufferArg>( this->args ).Get();
235 uint16_t timeout = pipelineTimeout < this->timeout ?
236 pipelineTimeout : this->timeout;
237 return this->zip->Read( offset, size, buffer, handler, timeout );
238 }
239 };
240
241 //----------------------------------------------------------------------------
243 //----------------------------------------------------------------------------
245 Arg<void*> buffer, uint16_t timeout = 0 )
246 {
247 return ZipReadImpl<false>( std::move( zip ), std::move( offset ), std::move( size ),
248 std::move( buffer ) ).Timeout( timeout );
249 }
250 //----------------------------------------------------------------------------
252 //----------------------------------------------------------------------------
253 template<bool HasHndl>
254 class ZipReadFromImpl: public ZipOperation<ZipReadFromImpl, HasHndl, Resp<ChunkInfo>,
255 Arg<std::string>, Arg<uint64_t>, Arg<uint32_t>, Arg<void*>>
256 {
257 public:
258
259 //------------------------------------------------------------------------
261 //------------------------------------------------------------------------
264
265 //------------------------------------------------------------------------
267 //------------------------------------------------------------------------
269
270 //------------------------------------------------------------------------
272 //------------------------------------------------------------------------
273 std::string ToString()
274 {
275 return "ZipReadFrom";
276 }
277
278 protected:
279
280 //------------------------------------------------------------------------
286 //------------------------------------------------------------------------
287 XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
288 {
289 std::string &fn = std::get<FileNameArg>( this->args ).Get();
290 uint64_t offset = std::get<OffsetArg>( this->args ).Get();
291 uint32_t size = std::get<SizeArg>( this->args ).Get();
292 void *buffer = std::get<BufferArg>( this->args ).Get();
293 uint16_t timeout = pipelineTimeout < this->timeout ?
294 pipelineTimeout : this->timeout;
295 return this->zip->ReadFrom( fn, offset, size, buffer, handler, timeout );
296 }
297 };
298
299 //----------------------------------------------------------------------------
301 //----------------------------------------------------------------------------
303 Arg<uint64_t> offset, Arg<uint32_t> size,
304 Arg<void*> buffer, uint16_t timeout = 0 )
305 {
306 return ZipReadFromImpl<false>( std::move( zip ), std::move( fn ), std::move( offset ),
307 std::move( size ), std::move( buffer ) ).Timeout( timeout );
308 }
309
310
311 //----------------------------------------------------------------------------
313 //----------------------------------------------------------------------------
314 template<bool HasHndl>
315 class ZipWriteImpl: public ZipOperation<ZipWriteImpl, HasHndl, Resp<void>,
316 Arg<uint32_t>, Arg<const void*>>
317 {
318 public:
319
320 //------------------------------------------------------------------------
322 //------------------------------------------------------------------------
325
326 //------------------------------------------------------------------------
328 //------------------------------------------------------------------------
330
331 //------------------------------------------------------------------------
333 //------------------------------------------------------------------------
334 std::string ToString()
335 {
336 return "ZipWrite";
337 }
338
339 protected:
340
341 //------------------------------------------------------------------------
347 //------------------------------------------------------------------------
348 XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
349 {
350 uint32_t size = std::get<SizeArg>( this->args ).Get();
351 const void *buffer = std::get<BufferArg>( this->args ).Get();
352 uint16_t timeout = pipelineTimeout < this->timeout ?
353 pipelineTimeout : this->timeout;
354 return this->zip->Write( size, buffer, handler, timeout );
355 }
356 };
357
358 //----------------------------------------------------------------------------
360 //----------------------------------------------------------------------------
362 uint16_t timeout = 0 )
363 {
364 return ZipWriteImpl<false>( std::move( zip ), std::move( size ),
365 std::move( buffer ) ).Timeout( timeout );
366 }
367
368
369 //----------------------------------------------------------------------------
371 //----------------------------------------------------------------------------
372 template<bool HasHndl>
373 class AppendFileImpl: public ZipOperation<AppendFileImpl, HasHndl, Resp<void>,
374 Arg<std::string>, Arg<uint32_t>, Arg<uint32_t>, Arg<const void*>>
375 {
376 public:
377
378 //------------------------------------------------------------------------
380 //------------------------------------------------------------------------
383
384 //------------------------------------------------------------------------
386 //------------------------------------------------------------------------
388
389 //------------------------------------------------------------------------
391 //------------------------------------------------------------------------
392 std::string ToString()
393 {
394 return "AppendFile";
395 }
396
397 protected:
398
399 //------------------------------------------------------------------------
405 //------------------------------------------------------------------------
406 XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
407 {
408 std::string &fn = std::get<FnArg>( this->args ).Get();
409 uint32_t crc32 = std::get<CrcArg>( this->args ).Get();
410 uint32_t size = std::get<SizeArg>( this->args ).Get();
411 const void *buffer = std::get<BufferArg>( this->args ).Get();
412 uint16_t timeout = pipelineTimeout < this->timeout ?
413 pipelineTimeout : this->timeout;
414 return this->zip->AppendFile( fn, crc32, size, buffer, handler, timeout );
415 }
416 };
417
418 //----------------------------------------------------------------------------
420 //----------------------------------------------------------------------------
422 Arg<uint32_t> crc32, Arg<uint32_t> size,
423 Arg<const void*> buffer, uint16_t timeout = 0 )
424 {
425 return AppendFileImpl<false>( std::move( zip ), std::move( fn ), std::move( crc32 ),
426 std::move( size ), std::move( buffer ) ).Timeout( timeout );
427 }
428
429
430 //----------------------------------------------------------------------------
432 //----------------------------------------------------------------------------
433 template<bool HasHndl>
434 class CloseFileImpl: public ZipOperation<CloseFileImpl, HasHndl, Resp<void>>
435 {
436 public:
437
438 //------------------------------------------------------------------------
440 //------------------------------------------------------------------------
442
443 //------------------------------------------------------------------------
445 //------------------------------------------------------------------------
446 std::string ToString()
447 {
448 return "ZipCloseFile";
449 }
450
451 private:
452
453 //------------------------------------------------------------------------
454 // this is not an async operation so we don't need a handler
455 //------------------------------------------------------------------------
456 using ZipOperation<CloseFileImpl, HasHndl, Resp<void>>::operator>>;
457
458 protected:
459
460 //------------------------------------------------------------------------
466 //------------------------------------------------------------------------
467 XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
468 {
469 XRootDStatus st = this->zip->CloseFile();
470 if( !st.IsOK() ) return st;
471 handler->HandleResponse( new XRootDStatus(), nullptr );
472 return XRootDStatus();
473 }
474 };
476
477
478 //----------------------------------------------------------------------------
480 //----------------------------------------------------------------------------
481 template<bool HasHndl>
482 class ZipStatImpl: public ZipOperation<ZipStatImpl, HasHndl, Resp<StatInfo>>
483 {
484 public:
485
486 //------------------------------------------------------------------------
488 //------------------------------------------------------------------------
490
491 //------------------------------------------------------------------------
493 //------------------------------------------------------------------------
494 std::string ToString()
495 {
496 return "ZipStat";
497 }
498
499 protected:
500
501 //------------------------------------------------------------------------
507 //------------------------------------------------------------------------
508 XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
509 {
510 StatInfo *info = nullptr;
511 XRootDStatus st = this->zip->Stat( info );
512 if( !st.IsOK() ) return st;
513 AnyObject *rsp = new AnyObject();
514 rsp->Set( info );
515 handler->HandleResponse( new XRootDStatus(), rsp );
516 return XRootDStatus();
517 }
518 };
519
520 //----------------------------------------------------------------------------
522 //----------------------------------------------------------------------------
524 {
525 return ZipStatImpl<false>( std::move( zip ) );
526 }
527
528
529 //----------------------------------------------------------------------------
531 //----------------------------------------------------------------------------
532 template<bool HasHndl>
533 class ZipListImpl: public ZipOperation<ZipListImpl, HasHndl, Resp<DirectoryList>>
534 {
535 public:
536
537 //------------------------------------------------------------------------
539 //------------------------------------------------------------------------
541
542 //------------------------------------------------------------------------
544 //------------------------------------------------------------------------
545 std::string ToString()
546 {
547 return "ZipStat";
548 }
549
550 protected:
551
552 //------------------------------------------------------------------------
558 //------------------------------------------------------------------------
559 XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
560 {
561 DirectoryList *list = nullptr;
562 XRootDStatus st = this->zip->List( list );
563 if( !st.IsOK() ) return st;
564 AnyObject *rsp = new AnyObject();
565 rsp->Set( list );
566 handler->HandleResponse( new XRootDStatus(), rsp );
567 return XRootDStatus();
568 }
569 };
570
571 //----------------------------------------------------------------------------
573 //----------------------------------------------------------------------------
575 {
576 return ZipListImpl<false>( std::move( zip ) );
577 }
578
579
580 //----------------------------------------------------------------------------
582 //----------------------------------------------------------------------------
583 template<bool HasHndl>
584 class CloseArchiveImpl: public ZipOperation<CloseArchiveImpl, HasHndl, Resp<void>>
585 {
586 public:
587
588 //------------------------------------------------------------------------
590 //------------------------------------------------------------------------
592
593 //------------------------------------------------------------------------
595 //------------------------------------------------------------------------
596 std::string ToString()
597 {
598 return "ZipClose";
599 }
600
601 protected:
602
603 //------------------------------------------------------------------------
609 //------------------------------------------------------------------------
610 XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
611 {
612 uint16_t timeout = pipelineTimeout < this->timeout ?
613 pipelineTimeout : this->timeout;
614 return this->zip->CloseArchive( handler, timeout );
615 }
616 };
617
618 //----------------------------------------------------------------------------
620 //----------------------------------------------------------------------------
621 inline CloseArchiveImpl<false> CloseArchive( Ctx<ZipArchive> zip, uint16_t timeout = 0 )
622 {
623 return CloseArchiveImpl<false>( std::move( zip ) ).Timeout( timeout );
624 }
625
626}
627
628#endif /* SRC_XRDCL_XRDCLZIPOPERATIONS_HH_ */
Definition XrdClAnyObject.hh:33
void Set(Type object, bool own=true)
Definition XrdClAnyObject.hh:59
AppendFile operation (.
Definition XrdClZipOperations.hh:375
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition XrdClZipOperations.hh:406
@ CrcArg
Definition XrdClZipOperations.hh:387
@ FnArg
Definition XrdClZipOperations.hh:387
@ BufferArg
Definition XrdClZipOperations.hh:387
@ SizeArg
Definition XrdClZipOperations.hh:387
std::string ToString()
Definition XrdClZipOperations.hh:392
Definition XrdClArg.hh:234
CloseArchive operation (.
Definition XrdClZipOperations.hh:585
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition XrdClZipOperations.hh:610
std::string ToString()
Definition XrdClZipOperations.hh:596
CloseFile operation (.
Definition XrdClZipOperations.hh:435
std::string ToString()
Definition XrdClZipOperations.hh:446
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition XrdClZipOperations.hh:467
Definition XrdClOperations.hh:552
std::tuple< Args... > args
Operation arguments.
Definition XrdClOperations.hh:771
Derived< HasHndl > Timeout(uint16_t timeout)
Set operation timeout.
Definition XrdClOperations.hh:681
uint16_t timeout
Operation timeout.
Definition XrdClOperations.hh:776
Directory list.
Definition XrdClXRootDResponses.hh:650
OpenArchive operation (.
Definition XrdClZipOperations.hh:79
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition XrdClZipOperations.hh:110
std::string ToString()
Definition XrdClZipOperations.hh:96
OpenFile operation (.
Definition XrdClZipOperations.hh:137
@ FlagsArg
Definition XrdClZipOperations.hh:149
@ Crc32Arg
Definition XrdClZipOperations.hh:149
@ FnArg
Definition XrdClZipOperations.hh:149
@ SizeArg
Definition XrdClZipOperations.hh:149
std::string ToString()
Definition XrdClZipOperations.hh:154
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition XrdClZipOperations.hh:168
std::unique_ptr< PipelineHandler > handler
Operation handler.
Definition XrdClOperations.hh:309
Definition XrdClOperations.hh:64
Object stat info.
Definition XrdClXRootDResponses.hh:400
Request status.
Definition XrdClXRootDResponses.hh:219
ZipList operation (.
Definition XrdClZipOperations.hh:534
std::string ToString()
Definition XrdClZipOperations.hh:545
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition XrdClZipOperations.hh:559
Definition XrdClZipOperations.hh:28
ZipOperation(ZipOperation< Derived, from, Response, Arguments... > &&op)
Definition XrdClZipOperations.hh:51
friend class ZipOperation
Definition XrdClZipOperations.hh:30
ZipOperation(Ctx< ZipArchive > zip, Arguments... args)
Definition XrdClZipOperations.hh:39
virtual ~ZipOperation()
Destructor.
Definition XrdClZipOperations.hh:60
Ctx< ZipArchive > zip
The file object itself.
Definition XrdClZipOperations.hh:70
Read operation (.
Definition XrdClZipOperations.hh:256
@ BufferArg
Definition XrdClZipOperations.hh:268
@ OffsetArg
Definition XrdClZipOperations.hh:268
@ FileNameArg
Definition XrdClZipOperations.hh:268
@ SizeArg
Definition XrdClZipOperations.hh:268
std::string ToString()
Definition XrdClZipOperations.hh:273
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition XrdClZipOperations.hh:287
Read operation (.
Definition XrdClZipOperations.hh:199
std::string ToString()
Definition XrdClZipOperations.hh:216
@ OffsetArg
Definition XrdClZipOperations.hh:211
@ BufferArg
Definition XrdClZipOperations.hh:211
@ SizeArg
Definition XrdClZipOperations.hh:211
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition XrdClZipOperations.hh:230
ZipStat operation (.
Definition XrdClZipOperations.hh:483
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition XrdClZipOperations.hh:508
std::string ToString()
Definition XrdClZipOperations.hh:494
Write operation (.
Definition XrdClZipOperations.hh:317
std::string ToString()
Definition XrdClZipOperations.hh:334
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition XrdClZipOperations.hh:348
@ BufferArg
Definition XrdClZipOperations.hh:329
@ SizeArg
Definition XrdClZipOperations.hh:329
Definition XrdClAction.hh:34
ZipListImpl< false > List(Ctx< ZipArchive > zip)
Factory for creating ZipStatImpl objects.
Definition XrdClZipOperations.hh:574
ReadImpl< false > Read(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, uint16_t timeout=0)
Factory for creating ReadImpl objects.
Definition XrdClFileOperations.hh:273
CloseArchiveImpl< false > CloseArchive(Ctx< ZipArchive > zip, uint16_t timeout=0)
Factory for creating CloseFileImpl objects.
Definition XrdClZipOperations.hh:621
StatImpl< false > Stat(Ctx< File > file, Arg< bool > force, uint16_t timeout=0)
Definition XrdClFileOperations.hh:535
AppendFileImpl< false > AppendFile(Ctx< ZipArchive > zip, Arg< std::string > fn, Arg< uint32_t > crc32, Arg< uint32_t > size, Arg< const void * > buffer, uint16_t timeout=0)
Factory for creating ArchiveReadImpl objects.
Definition XrdClZipOperations.hh:421
CloseFileImpl< false > CloseFile
Definition XrdClZipOperations.hh:475
OpenFileImpl< false > OpenFile(Ctx< ZipArchive > zip, Arg< std::string > fn, Arg< OpenFlags::Flags > flags=OpenFlags::None, Arg< uint64_t > size=0, Arg< uint32_t > crc32=0, uint16_t timeout=0)
Factory for creating OpenFileImpl objects.
Definition XrdClZipOperations.hh:184
ZipReadFromImpl< false > ReadFrom(Ctx< ZipArchive > zip, Arg< std::string > fn, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, uint16_t timeout=0)
Factory for creating ArchiveReadImpl objects.
Definition XrdClZipOperations.hh:302
WriteImpl< false > Write(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< const void * > buffer, uint16_t timeout=0)
Factory for creating WriteImpl objects.
Definition XrdClFileOperations.hh:591
OpenArchiveImpl< false > OpenArchive(Ctx< ZipArchive > zip, Arg< std::string > fn, Arg< OpenFlags::Flags > flags, uint16_t timeout=0)
Factory for creating OpenArchiveImpl objects.
Definition XrdClZipOperations.hh:123
Definition XrdOucJson.hh:4517
Utility class for storing a pointer to operation context.
Definition XrdClCtx.hh:39
Flags
Open flags, may be or'd when appropriate.
Definition XrdClFileSystem.hh:76
@ None
Nothing.
Definition XrdClFileSystem.hh:77
Definition XrdClOperationHandlers.hh:662
bool IsOK() const
We're fine.
Definition XrdClStatus.hh:124