ErrorCode processDcacheCmd()

in aios/filesystem/fslib/tools/dcacheutil/DcacheUtilMain.cpp [258:365]


ErrorCode processDcacheCmd(int argc, char** argv, DcacheConf &conf) {
    ErrorCode ret = EC_UNKNOWN;
    auto begin = autil::TimeUtility::currentTime();
    if (argc >= 2) {
        if (strcmp(argv[1], FsUtil::COPY_CMD.c_str()) == 0) {
            bool recursive = false;
            char* srcPath = NULL;
            char* dstPath = NULL;
            if (argc >= 5 && strcmp(argv[2], "-r") == 0) {
                recursive = true;
                srcPath = argv[3];
                dstPath = argv[4];
            } else if (argc >= 4) {
                recursive = false;
                srcPath = argv[2];
                dstPath = argv[3];
            } else {
                return ret;
            }
            BatchCopyItem copyItem(srcPath, dstPath, conf.md5);
            if (conf.warmup) {
                warmUpRemote(vector<BatchCopyItem>{copyItem}, conf);
            }
            ret = runCopy(conf, copyItem, recursive);
            return ret;
        } else if (strcmp(argv[1], "batchCp") == 0) {
            bool recursive = false;
            char* itemsStr = NULL;
            if (argc >= 4 && strcmp(argv[2], "-r") == 0) {
                recursive = true;
                itemsStr = argv[3];
            } else if (argc >= 3) {
                recursive = false;
                itemsStr = argv[2];
            } else {
                return ret;
            }
            vector<BatchCopyItem> items;
            try {
                FromJsonString(items, itemsStr);
            } catch (const autil::legacy::ExceptionBase& e) {
                cerr << "parse batch copy items err:" << e.GetMessage().c_str() << endl;
                return EC_BADARGS;
            }
            
            autil::ThreadPool threadPool;
            threadPool.start("download");
            if (conf.warmup) {
                auto task = [&items, &conf]() {
                                warmUpRemote(items, conf);
                            };
                if (autil::ThreadPool::ERROR_NONE != threadPool.pushTask(task)) {
                    warmUpRemote(items, conf);
                }
            }

            for (auto it = items.begin(); it != items.end(); ++it) {
                auto task = [&ret, &conf, it, recursive]() {
                                auto curRet = runCopy(conf, *it, recursive);
                                if (curRet != EC_OK) {
                                    cerr << "failed to get " << it->src << " ret:"<< ret << endl;
                                    ret = curRet;
                                }
                            };
                if (autil::ThreadPool::ERROR_NONE != threadPool.pushTask(task)) {
                    ret = runCopy(conf, *it, recursive);
                    if (ret != EC_OK) {
                        return ret;
                    }
                }
            }
            threadPool.waitFinish();
            AUTIL_LOG(INFO, "batch copy %s cost:%ldms", itemsStr, (autil::TimeUtility::currentTime() - begin) / 1000);
            return ret;
        } else if (strcmp(argv[1], FsUtil::LISTDIR_CMD.c_str()) == 0) {
            if (argc == 3) {
                return FsUtil::runListDir(convertToDcacheUrl(argv[2], conf).c_str());
            } else if (argc == 4) {
                if (strcmp(argv[3], "-R") == 0){
                    return FsUtil::runListDirWithRecursive(convertToDcacheUrl(argv[2], conf).c_str(), "");
                } else if (strcmp(argv[2], "-R") == 0){
                    return FsUtil::runListDirWithRecursive(convertToDcacheUrl(argv[3], conf).c_str(), "");
                }
            } else if (argc == 5){
                if (strcmp(argv[3], "-R") == 0) {
                    return FsUtil::runListDirWithRecursive(convertToDcacheUrl(argv[2], conf).c_str(), argv[4]);
                } else if (strcmp(argv[2], "-R") == 0){
                    return FsUtil::runListDirWithRecursive(convertToDcacheUrl(argv[4], conf).c_str(), argv[3]);
                }
            } 
        } else if (strcmp(argv[1], FsUtil::CAT_CMD.c_str()) == 0 &&
                   argc == 3) 
        {
            return FsUtil::runCat(convertToDcacheUrl(argv[2], conf).c_str());
        } else if (strcmp(argv[1], FsUtil::GETMETA_CMD.c_str()) == 0 &&
                   argc == 3) 
        {
            return FsUtil::runGetMeta(convertToDcacheUrl(argv[2], conf).c_str());
        } else if (strcmp(argv[1], FsUtil::ISEXIST_CMD.c_str()) == 0 &&
                   argc == 3) 
        {
            return FsUtil::runIsExist(convertToDcacheUrl(argv[2], conf).c_str());
        }
    }
    
    printDcacheUtilCmdUsage();
    return EC_BADARGS;
}