int
moveToPreloadedDir (const char *path, const char *iRODSPath) {
    int status;
    char preloadCachePath[MAX_NAME_LEN];

    if (path == NULL || iRODSPath == NULL) {
        rodsLog (LOG_ERROR, "moveToPreloadedDir: input path or iRODSPath is NULL");
        return (SYS_INTERNAL_NULL_INPUT_ERR);
    }

    status = _getCachePath(iRODSPath, preloadCachePath);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "moveToPreloadedDir: _getCachePath error.");
        rodsLog (LOG_ERROR, "moveToPreloadedDir: failed to get cache path - %s", path);
        return status;
    }

    // make dir
    prepareDir(preloadCachePath);
    
    // move the file
    status = rename(path, preloadCachePath);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "moveToPreloadedDir: rename error.");
        return status;
    }

    return (0);
}
Example #2
0
QString K3b::findUniqueFilePrefix( const QString& _prefix, const QString& path )
{
    QString url;
    if( path.isEmpty() || !QFile::exists(path) )
        url = defaultTempPath();
    else
        url = prepareDir( path );

    QString prefix = _prefix;
    if( prefix.isEmpty() )
        prefix = "k3b_";

    // now create the unique prefix
    QDir dir( url );
    QStringList entries = dir.entryList( QDir::NoFilter, QDir::Name );
    int i = 0;
    for( QStringList::iterator it = entries.begin();
         it != entries.end(); ++it ) {
        if( (*it).startsWith( prefix + QString::number(i) ) ) {
            i++;
            it = entries.begin();
        }
    }

    return url + prefix + QString::number(i);
}
void DataExporter::startIO(const QString &path)
{
    if (!prepareDir(path, m_dir)) {
        fail(QString("Fail to prepare directory %1").arg(path));
        return;
    } else if (!m_dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot).isEmpty()) {
        fail(QString("Target directory %1 is not empty").arg(m_dir.path()));
        return;
    }

    if (!m_db->size()) {
        qCInfo(DATA_IO_CATEGORY) << "No data to export";
        QCoreApplication::quit();
        return;
    }

    m_db->getStoredCategories();
}
static int
_download(const char *path, struct stat *stbufIn) {
    int status;
    rcComm_t *conn;
    rodsPathInp_t rodsPathInp;
    rErrMsg_t errMsg;
    char preloadCachePath[MAX_NAME_LEN];
    char preloadCacheWorkPath[MAX_NAME_LEN];

    // set path for getUtil
    status = _getCachePath(path, preloadCachePath);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "_download: _getCachePath error.");
        rodsLog (LOG_ERROR, "_download: failed to get cache path - %s", path);
        return status;
    }

    status = _getCacheWorkPath(path, preloadCacheWorkPath);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "_download: _getCacheWorkPath error.");
        rodsLog (LOG_ERROR, "_download: failed to get cache work path - %s", path);
        return status;
    }

    rodsLog (LOG_DEBUG, "_download: download %s to %s", path, preloadCachePath);

    // set src path
    memset( &rodsPathInp, 0, sizeof( rodsPathInp_t ) );
    addSrcInPath( &rodsPathInp, (char*)path );
    status = parseRodsPath (&rodsPathInp.srcPath[0], PreloadRodsEnv);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "_download: parseRodsPath error.");
        return status;
    }

    // set dest path
    rodsPathInp.destPath = ( rodsPath_t* )malloc( sizeof( rodsPath_t ) );
    memset( rodsPathInp.destPath, 0, sizeof( rodsPath_t ) );
    rstrcpy( rodsPathInp.destPath->inPath, preloadCacheWorkPath, MAX_NAME_LEN );
    status = parseLocalPath (rodsPathInp.destPath);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "_download: parseLocalPath error.");
        return status;
    }

    // Connect
    conn = rcConnect (PreloadRodsEnv->rodsHost, PreloadRodsEnv->rodsPort, PreloadRodsEnv->rodsUserName, PreloadRodsEnv->rodsZone, RECONN_TIMEOUT, &errMsg);
    if (conn == NULL) {
        rodsLog (LOG_ERROR, "_download: error occurred while connecting to irods");
        return -EPIPE;
    }

    // Login
    if (strcmp (PreloadRodsEnv->rodsUserName, PUBLIC_USER_NAME) != 0) { 
        status = clientLogin(conn);
        if (status != 0) {
            rodsLogError(LOG_ERROR, status, "_download: ClientLogin error.");
            rcDisconnect(conn);
            return status;
        }
    }

    // make dir
    prepareDir(preloadCachePath);

    // Preload
    rodsLog (LOG_DEBUG, "_download: download %s", path);
    status = getUtil (&conn, PreloadRodsEnv, PreloadRodsArgs, &rodsPathInp);
    rodsLog (LOG_DEBUG, "_download: complete downloading %s", path);

    // Disconnect 
    rcDisconnect(conn);

    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "_download: getUtil error.");
        return status;
    }

    // be careful when using Lock
    LOCK(PreloadLock);
    status = _completeDownload(preloadCacheWorkPath, preloadCachePath, stbufIn);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "_download: _completeDownload error.");
        UNLOCK(PreloadLock);
        return status;
    }

    UNLOCK(PreloadLock);
    return 0;
}
Example #5
0
QString K3b::defaultTempPath()
{
    return prepareDir( k3bcore->globalSettings()->defaultTempPath() );
}