]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Fix rados put from '-' (stdin)
authorDan Mick <dan.mick@inktank.com>
Fri, 31 Aug 2012 21:41:29 +0000 (14:41 -0700)
committerDan Mick <dan.mick@inktank.com>
Fri, 31 Aug 2012 22:45:24 +0000 (15:45 -0700)
Signed-off-by: Dan Mick <dan.mick@inktank.com>
Reviewed-by: Mike Ryan <mike.ryan@inktank.com>
Reviewed-by: Greg Farnum <gregory.farnum@inktank.com>
Fixes: #3068
src/rados.cc

index 50131e32f94c9fff0916bfba06d9e958d6d9b6ce..8cf71c79ac41a0adce32ca3dcaed40feaf4c51cc 100644 (file)
@@ -327,48 +327,44 @@ static int do_put(IoCtx& io_ctx, const char *objname, const char *infile, int op
   if (check_stdio && strcmp(infile, "-") == 0)
     stdio = true;
 
-  if (stdio) {
-    char buf[256];
-    while(!cin.eof()) {
-      cin.getline(buf, 256);
-      indata.append(buf);
-      indata.append('\n');
-    }
-  } else {
-    int ret, fd = open(infile, O_RDONLY);
-    if (fd < 0) {
-      char buf[80];
-      cerr << "error reading input file " << infile << ": " << strerror_r(errno, buf, sizeof(buf)) << std::endl;
-      return 1;
-    }
-    char *buf = new char[op_size];
-    int count = op_size;
-    uint64_t offset = 0;
-    while (count == op_size) {
-      count = read(fd, buf, op_size);
-      if (count == 0) {
-        if (!offset) {
-          int ret = io_ctx.create(oid, true);
-          if (ret < 0)
-            cerr << "WARNING: could not create object: " << oid << std::endl;
-        }
-        continue;
+  int ret;
+  int fd = 0;
+  if (!stdio)
+    fd = open(infile, O_RDONLY);
+  if (fd < 0) {
+    char buf[80];
+    cerr << "error reading input file " << infile << ": " << strerror_r(errno, buf, sizeof(buf)) << std::endl;
+    return 1;
+  }
+  char *buf = new char[op_size];
+  int count = op_size;
+  uint64_t offset = 0;
+  while (count != 0) {
+    count = read(fd, buf, op_size);
+    if (count == 0) {
+      if (!offset) {
+       int ret = io_ctx.create(oid, true);
+       if (ret < 0) {
+         cerr << "WARNING: could not create object: " << oid << std::endl;
+         return 1;
+       }
       }
-      indata.append(buf, count);
-      if (offset == 0)
-       ret = io_ctx.write_full(oid, indata);
-      else
-       ret = io_ctx.write(oid, indata, count, offset);
-      indata.clear();
+      continue;
+    }
+    indata.append(buf, count);
+    if (offset == 0)
+      ret = io_ctx.write_full(oid, indata);
+    else
+      ret = io_ctx.write(oid, indata, count, offset);
+    indata.clear();
 
-      if (ret < 0) {
-        close(fd);
-        return ret;
-      }
-      offset += count;
+    if (ret < 0) {
+      close(fd);
+      return ret;
     }
-    close(fd);
+    offset += count;
   }
+  close(fd);
   return 0;
 }