XRootD
XrdOssArcZipFile Class Reference

#include <XrdOssArcZipFile.hh>

+ Collaboration diagram for XrdOssArcZipFile:

Public Member Functions

 XrdOssArcZipFile (const char *path, int &rc)
 
 ~XrdOssArcZipFile ()
 
int Close ()
 
int Open (const char *member)
 
ssize_t Read (void *buff, off_t offset, size_t blen)
 
int Stat (const char *mName, struct stat &buf)
 
int Stat (struct stat &buf)
 

Detailed Description

Definition at line 45 of file XrdOssArcZipFile.hh.

Constructor & Destructor Documentation

◆ XrdOssArcZipFile()

XrdOssArcZipFile::XrdOssArcZipFile ( const char *  path,
int &  rc 
)

Definition at line 60 of file XrdOssArcZipFile.cc.

61 {
62  XrdOucEnv zipEnv;
63  int zFD, zrc;
64 
65 // Try to open the file. We only support read mode.
66 //
67  if ((zFD = XrdSysFD_Open(path, O_RDONLY)) < 0)
68  {rc = -errno;
69  return;
70  }
71 
72 // Get the stat information for the archive now using the retrned FD as
73 // as attaching the FD to a zipfile "destroys" the original FD.
74 //
75  if (fstat(zFD, &zFStat)) memset(&zFStat, 0, sizeof(zFStat));
76 
77 // Record path
78 //
79  zPath = strdup(path);
80 
81 // Convert open to archive open
82 //
83  if ((zFile = zip_fdopen(zFD, ZIP_CHECKCONS, &zrc)) == 0)
84  {rc = zip2syserr("fdopen", zrc);
85  close(zFD);
86  return;
87  }
88 }
#define close(a)
Definition: XrdPosix.hh:48
#define fstat(a, b)
Definition: XrdPosix.hh:109

References close, and fstat.

◆ ~XrdOssArcZipFile()

XrdOssArcZipFile::~XrdOssArcZipFile ( )

Definition at line 94 of file XrdOssArcZipFile.cc.

95 {
96 // If we have an open subfile, close it
97 //
98  if (zSubFile) Close();
99 
100 // Close the archive itself
101 //
102  if (zFile)
103  {if (zip_close(zFile))
104  {zipEmsg("close", zip_get_error(zFile));
105  zip_discard(zFile);
106  }
107  zFile = 0;
108  }
109 
110 // Free up any storage
111 //
112  if (zPath) free(zPath);
113 }

References XrdCl::Close().

+ Here is the call graph for this function:

Member Function Documentation

◆ Close()

int XrdOssArcZipFile::Close ( )

Definition at line 119 of file XrdOssArcZipFile.cc.

120 {
121  int zrc = 0;
122 
123 // Close the member subfile if it is open
124 //
125  if (zSubFile)
126  {if ((zrc = zip_fclose(zSubFile))) zrc = zip2syserr("close member", zrc);
127  zSubFile = 0;
128  }
129 
130 // Remove all vestigaes of this subfile
131 //
132  if (zMember) {free(zMember); zMember = 0;}
133 
134 // All done
135 //
136  return zrc;
137 }

◆ Open()

int XrdOssArcZipFile::Open ( const char *  member)

Definition at line 143 of file XrdOssArcZipFile.cc.

144 {
145  int rc;
146 
147 // Make sure we have an open archive here
148 //
149  if (zFile == 0) return -EBADF;
150 
151 // If an archive member is alreaddy open then close it
152 //
153  if (zSubFile)
154  {if ((rc = zip_fclose(zSubFile))) zip2syserr("close", rc, true);
155  free(zMember);
156  zMember = 0;
157  zSubFile = 0;
158  }
159 
160 // Set member name we are handling
161 //
162  if (zMember) free(zMember);
163  zMember = strdup(member);
164 
165 // Open the archive member
166 //
167  zSubFile = zip_fopen(zFile, zMember, 0);
168  if (zSubFile == 0) return zip2syserr("open", zip_get_error(zFile));
169 
170 // We should check if this is a compressed archive as ther can onl be read
171 // sequentially. However, that is not supported until v 10.1 and the current
172 // rpms available at 1.7. So, we punt on this and assume it not compressed and
173 // is seekable. Note that compressed files are not seekable.
174 //
175 // zSeek = zip_file_is_seekable(zSubFile) == 1;
176  zSeek = true;
177  zOffset = 0;
178 
179 // All done
180 //
181  return 0;
182 }

◆ Read()

ssize_t XrdOssArcZipFile::Read ( void *  buff,
off_t  offset,
size_t  blen 
)

Definition at line 188 of file XrdOssArcZipFile.cc.

189 {
190 // Make sure this file is actually open
191 //
192  if (zSubFile == 0) return -EBADF;
193  if (!blen) return 0;
194 
195 // If this file does not support seeks, return a seek error if a seek wanted
196 //
197  if (offset != zOffset)
198  {if (!zSeek) return -ESPIPE;
199  if (zip_fseek(zSubFile, offset, SEEK_SET))
200  return zip2syserr("seek into", zip_file_get_error(zSubFile));
201  zEOF = false;
202  }
203 
204 // Check if we have reached EOF
205 //
206  if (zEOF) return 0;
207 
208 // Perform the read
209 //
210  zip_int64_t ret = zip_fread(zSubFile, buff, blen);
211  if (ret < 0)
212  return zip2syserr("read", zip_file_get_error(zSubFile));
213 
214 // Update offset and check for EOF
215 //
216  zOffset += ret;
217  if (ret < (zip_int64_t)blen) zEOF = true;
218  return ret;
219 }

◆ Stat() [1/2]

int XrdOssArcZipFile::Stat ( const char *  mName,
struct stat buf 
)

Definition at line 258 of file XrdOssArcZipFile.cc.

259 {
260  zip_stat_t zStat;
261 
262 // Iniialize the stat buffer
263 //
264  memcpy(&buf, &zFStat, sizeof(struct stat));
265 
266 // Clear the stat structures
267 //
268  zip_stat_init(&zStat);
269 
270 // Get information
271 //
272  if (zip_stat(zFile, mName, 0, &zStat) < 0)
273  return zip2syserr("stat", zip_get_error(zFile));
274 
275 // Copy the relevant information
276 //
277  if (zStat.valid & ZIP_STAT_INDEX) buf.st_ino = zStat.index;
278  if (zStat.valid & ZIP_STAT_SIZE) buf.st_size = zStat.size;
279 
280 // All done
281 //
282  return 0;
283 }
#define stat(a, b)
Definition: XrdPosix.hh:105

References stat.

◆ Stat() [2/2]

int XrdOssArcZipFile::Stat ( struct stat buf)

Definition at line 225 of file XrdOssArcZipFile.cc.

226 {
227  zip_stat_t zStat;
228 
229 // Make sure this file is actually open
230 //
231  if (zSubFile == 0) return -EBADF;
232 
233 // Iniialize the stat buffer
234 //
235  memcpy(&buf, &zFStat, sizeof(struct stat));
236 
237 // Clear the stat structures
238 //
239  zip_stat_init(&zStat);
240 
241 // Get information
242 //
243  if (zip_stat(zFile, zMember, 0, &zStat) < 0)
244  return zip2syserr("stat", zip_get_error(zFile));
245 
246 // Copy the relevant information
247 //
248  if (zStat.valid & ZIP_STAT_INDEX) buf.st_ino = zStat.index;
249  if (zStat.valid & ZIP_STAT_SIZE) buf.st_size = zStat.size;
250 
251 // All done
252 //
253  return 0;
254 }

References stat.


The documentation for this class was generated from the following files: