| 844 | } |
| 845 | |
| 846 | int ObjectStoreTool::export_file(ObjectStore *store, coll_t cid, ghobject_t &obj, bool force) |
| 847 | { |
| 848 | struct stat st; |
| 849 | mysize_t total; |
| 850 | footer ft; |
| 851 | |
| 852 | auto ch = store->open_collection(cid); |
| 853 | if (!ch) { |
| 854 | cerr << "Collection " << cid << " does not exist" << std::endl; |
| 855 | return -ENOENT; |
| 856 | } |
| 857 | int ret = store->stat(ch, obj, &st); |
| 858 | if (ret < 0) |
| 859 | return ret; |
| 860 | |
| 861 | cerr << "Read " << obj << std::endl; |
| 862 | |
| 863 | total = st.st_size; |
| 864 | if (debug) |
| 865 | cerr << "size=" << total << std::endl; |
| 866 | |
| 867 | object_begin objb(obj); |
| 868 | |
| 869 | { |
| 870 | bufferptr bp; |
| 871 | bufferlist bl; |
| 872 | ret = store->getattr(ch, obj, OI_ATTR, bp); |
| 873 | if (ret < 0) { |
| 874 | cerr << "getattr failure: " << cpp_strerror(ret) |
| 875 | << " at obj:" << obj |
| 876 | << (force ? " IGNORED" : "") |
| 877 | << std::endl; |
| 878 | if (!force) { |
| 879 | return ret; |
| 880 | } |
| 881 | } else { |
| 882 | bl.push_back(bp); |
| 883 | decode(objb.oi, bl); |
| 884 | if (debug) |
| 885 | cerr << "object_info: " << objb.oi << std::endl; |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | // NOTE: we include whiteouts, lost, etc. |
| 890 | |
| 891 | ret = write_section(TYPE_OBJECT_BEGIN, objb, file_fd); |
| 892 | if (ret < 0) |
| 893 | return ret; |
| 894 | |
| 895 | uint64_t offset = 0; |
| 896 | bufferlist rawdatabl; |
| 897 | while(total > 0) { |
| 898 | rawdatabl.clear(); |
| 899 | mysize_t len = max_read; |
| 900 | if (len > total) |
| 901 | len = total; |
| 902 | |
| 903 | ret = store->read(ch, obj, offset, len, rawdatabl); |
nothing calls this directly
no test coverage detected