Attachment 'lfc-sfn2lfn.cc'
Download 1 #include <iostream>
2 #include <fstream>
3 #include <cstdlib>
4
5 #include "lfc_api.h"
6 #include "serrno.h"
7
8 int main(int argc, char *argv[])
9 {
10 if (argc != 3) {
11 std::cerr << "Usage: " << argv[0] << " SFNFILE LFNFILE" << std::endl;
12 return 1;
13 }
14
15 std::ifstream in(argv[1]);
16 std::ofstream out(argv[2]);
17
18 if (!in) {
19 std::cerr << argv[0] << ": " << argv[1] << ": Could not be opened for reading" << std::endl;
20 return 1;
21 }
22 if (!out) {
23 std::cerr << argv[0] << ": " << argv[2] << ": Could not be opened for writing" << std::endl;
24 return 1;
25 }
26 if (lfc_startsess(getenv("LFC_HOST"), "Looking up links of SFNs")) {
27 std::cerr << argv[0] << ": " << sstrerror(serrno) << std::endl;
28 return 1;
29 }
30
31 std::string sfn;
32 while (in >> sfn) {
33 struct lfc_filestatg statbuf;
34 struct lfc_linkinfo *links;
35 int numlinks;
36
37 if (lfc_statr(sfn.c_str(), &statbuf) || lfc_getlinks(0, statbuf.guid, &numlinks, &links)) {
38 std::cerr << argv[0] << ": " << sfn << ": " << sstrerror(serrno) << std::endl;
39 continue;
40 }
41 if (numlinks == 0) {
42 std::cerr << argv[0] << ": " << sfn << ": No links found" << std::endl;
43 } else for (int i = 0; i < numlinks; ++i) {
44 out << "lfn:" << links[i].path;
45 if (i < numlinks - 1) out << "\t";
46 else out << std::endl;
47 }
48 std::free(links);
49 }
50
51 lfc_endsess();
52 out.close();
53 in.close();
54 }
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.