Switch to stdio-based I/O for writing descriptor file.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Fri, 17 Aug 2007 04:38:25 +0000 (21:38 -0700)
committerMichael Vrable <mvrable@turin.ucsd.edu>
Fri, 17 Aug 2007 04:38:25 +0000 (21:38 -0700)
This should be a little bit easier to hook into filtering code (we can open
the output file, spawn the filter, and then fdopen the resulting
descriptor), which will be used when implementing signing of the descriptor
files.

scandir.cc

index 2d5a3a8..44aedd2 100644 (file)
@@ -767,26 +767,29 @@ int main(int argc, char *argv[])
     if (backup_scheme.size() > 0)
         desc_filename += backup_scheme + "-";
     desc_filename = desc_filename + desc_buf + ".lbs";
-    std::ofstream descriptor(desc_filename.c_str());
+    FILE *descriptor = fopen(desc_filename.c_str(), "w");
 
-    descriptor << "Format: LBS Snapshot v0.2\n";
-    descriptor << "Producer: LBS " << lbs_version << "\n";
+    fprintf(descriptor, "Format: LBS Snapshot v0.2\n");
+    fprintf(descriptor, "Producer: LBS %s\n", lbs_version);
     strftime(desc_buf, sizeof(desc_buf), "%Y-%m-%d %H:%M:%S %z", &time_buf);
-    descriptor << "Date: " << desc_buf << "\n";
+    fprintf(descriptor, "Date: %s\n", desc_buf);
     if (backup_scheme.size() > 0)
-        descriptor << "Scheme: " << backup_scheme << "\n";
-    descriptor << "Root: " << backup_root << "\n";
+        fprintf(descriptor, "Scheme: %s\n", backup_scheme.c_str());
+    fprintf(descriptor, "Root: %s\n", backup_root.c_str());
 
     SHA1Checksum checksum_csum;
     if (checksum_csum.process_file(checksum_filename.c_str())) {
-        descriptor << "Checksums: " << checksum_csum.checksum_str() << "\n";
+        string csum = checksum_csum.checksum_str();
+        fprintf(descriptor, "Checksums: %s\n", csum.c_str());
     }
 
-    descriptor << "Segments:\n";
+    fprintf(descriptor, "Segments:\n");
     for (std::set<string>::iterator i = segment_list.begin();
          i != segment_list.end(); ++i) {
-        descriptor << "    " << *i << "\n";
+        fprintf(descriptor, "    %s\n", i->c_str());
     }
 
+    fclose(descriptor);
+
     return 0;
 }