XRootD
XrdCks.cc File Reference
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <cerrno>
#include "XrdCks/XrdCksXAttr.hh"
#include "XrdOuc/XrdOucXAttr.hh"
+ Include dependency graph for XrdCks.cc:

Go to the source code of this file.

Functions

void Display ()
 
int main (int argc, char *argv[])
 
void Unable (int rc)
 
void Usage (int rc)
 

Variables

const char * csCmd
 
struct stat Stat
 
XrdOucXAttr< XrdCksXAttrxCS
 

Function Documentation

◆ Display()

void Display ( )

Definition at line 56 of file XrdCks.cc.

57 {
58  const char *stale;
59  char csBuff[512];
60 
61 // Check if the checksum is stale
62 //
63  if (xCS.Attr.Cks.fmTime != Stat.st_mtime) stale = " stale";
64  else stale = "";
65 
66 // Get displayable checksum
67 //
68  xCS.Attr.Cks.Get(csBuff, sizeof(csBuff));
69 
70 // Display the information
71 //
72  std::cout <<xCS.Attr.Cks.Name<<' '<<csBuff<<stale<<std::endl;
73 }
struct stat Stat
Definition: XrdCks.cc:49
XrdOucXAttr< XrdCksXAttr > xCS
Definition: XrdCks.cc:48

References Stat, and xCS.

Referenced by main().

+ Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 108 of file XrdCks.cc.

109 {
110  char *csName, *csPath, *csVal;
111  int rc;
112 
113 // Make sure the right number of arguments are here
114 //
115  if (argc <= 2)
116  {if (argc > 1 && !strcmp(argv[1], "-h")) Usage(0);
117  Usage(1);
118  }
119 
120 // Verify the name
121 //
122  csName = argv[2];
123  if (!xCS.Attr.Cks.Set(csName))
124  {std::cerr <<"xrdsetcks: checksum name '"<<csName<<"' is invalid"<<std::endl;
125  exit(3);
126  }
127 
128 // Determine what we should be doing
129 //
130  if (argc < 3) csCmd = "query";
131  else {csVal = argv[3];
132  if (!strcmp("delete", csVal)) csCmd = "delete";
133  else {csCmd = "set";
134  if (strncmp("0x", csVal, 2)) csVal += 2;
135  if (!xCS.Attr.Cks.Set(csVal, strlen(csVal)))
136  {std::cerr <<"xrdcks: checksum value is invalid"
137  <<std::endl;
138  exit(3);
139  }
140  }
141  }
142 
143 // Verify the path
144 //
145  csPath = argv[1];
146  if (stat(csPath, &Stat)) Unable(errno);
147 
148 // Handle query request
149 //
150  if (*csCmd == 'q')
151  {if ((rc = xCS.Get(csPath))) Unable(rc);
152  if (strcmp(xCS.Attr.Cks.Name, csName)) Unable(EILSEQ);
153  Display();
154  exit(0);
155  }
156 
157 // Handle delete
158 //
159  if (*csCmd == 'd')
160  {if ((rc = xCS.Del(csPath))) Unable(rc);
161  exit(0);
162  }
163 
164 // Handle the set
165 //
166  xCS.Attr.Cks.fmTime = static_cast<long long>(Stat.st_mtime);
167  xCS.Attr.Cks.csTime = 0;
168  if ((rc = xCS.Set(csPath))) Unable(rc);
169  exit(0);
170 }
void Unable(int rc)
Definition: XrdCks.cc:79
const char * csCmd
Definition: XrdCks.cc:50
void Display()
Definition: XrdCks.cc:56
void Usage(int rc)
Definition: XrdCks.cc:93
int stat(const char *path, struct stat *buf)

References csCmd, Display(), Stat, stat(), Unable(), Usage(), and xCS.

+ Here is the call graph for this function:

◆ Unable()

void Unable ( int  rc)

Definition at line 79 of file XrdCks.cc.

80 {
81  char eBuff[256];
82  if (rc < 0) rc = -rc;
83  snprintf(eBuff, sizeof(eBuff), "%s", strerror(rc));
84  *eBuff = tolower(*eBuff);
85  std::cerr<<"xrdcks: Unable to "<<csCmd<<" checksum; "<<eBuff<<std::endl;
86  exit(5);
87 }

References csCmd.

Referenced by main().

+ Here is the caller graph for this function:

◆ Usage()

void Usage ( int  rc)

Definition at line 93 of file XrdCks.cc.

94 {
95  std::cerr <<"Usage: xrdcks <path> <cksname> [<cksval>|delete]\n"
96  " xrdcks -h\n\n"
97  "Where: <path> - path to the target file\n"
98  " <cksname> - checksum name (e.g. adler32)\n"
99  " <cksval> - ASCII hex of value (even number of digits)"
100  <<std::endl;
101  exit(rc);
102 }

Referenced by main().

+ Here is the caller graph for this function:

Variable Documentation

◆ csCmd

const char* csCmd

Definition at line 50 of file XrdCks.cc.

Referenced by main(), and Unable().

◆ Stat

◆ xCS