コード例 #1
0
ファイル: trashimpl.cpp プロジェクト: Fat-Zer/tdebase
bool TrashImpl::deleteInfo( int trashId, const TQString& fileId )
{
    bool ok = TQFile::remove( infoPath( trashId, fileId ) );
    if ( ok )
        fileRemoved();
    return ok;
}
コード例 #2
0
ファイル: trashimpl.cpp プロジェクト: Fat-Zer/tdebase
bool TrashImpl::infoForFile( int trashId, const TQString& fileId, TrashedFileInfo& info )
{
    kdDebug() << k_funcinfo << trashId << " " << fileId << endl;
    info.trashId = trashId; // easy :)
    info.fileId = fileId; // equally easy
    info.physicalPath = filesPath( trashId, fileId );
    return readInfoFile( infoPath( trashId, fileId ), info, trashId );
}
コード例 #3
0
ファイル: trashimpl.cpp プロジェクト: Fat-Zer/tdebase
bool TrashImpl::emptyTrash()
{
    kdDebug() << k_funcinfo << endl;
    // The naive implementation "delete info and files in every trash directory"
    // breaks when deleted directories contain files owned by other users.
    // We need to ensure that the .trashinfo file is only removed when the
    // corresponding files could indeed be removed.

    const TrashedFileInfoList fileInfoList = list();

    TrashedFileInfoList::const_iterator it = fileInfoList.begin();
    const TrashedFileInfoList::const_iterator end = fileInfoList.end();
    for ( ; it != end ; ++it ) {
        const TrashedFileInfo& info = *it;
        const TQString filesPath = info.physicalPath;
        if ( synchronousDel( filesPath, true, true ) ) {
            TQFile::remove( infoPath( info.trashId, info.fileId ) );
        } // else error code is set
    }
    fileRemoved();

    return m_lastErrorCode == 0;
}
コード例 #4
0
ファイル: trashimpl.cpp プロジェクト: Fat-Zer/tdebase
bool TrashImpl::del( int trashId, const TQString& fileId )
{
    TQString info = infoPath(trashId, fileId);
    TQString file = filesPath(trashId, fileId);

    TQCString info_c = TQFile::encodeName(info);

    KDE_struct_stat buff;
    if ( KDE_lstat( info_c.data(), &buff ) == -1 ) {
        if ( errno == EACCES )
            error( TDEIO::ERR_ACCESS_DENIED, file );
        else
            error( TDEIO::ERR_DOES_NOT_EXIST, file );
        return false;
    }

    if ( !synchronousDel( file, true, TQFileInfo(file).isDir() ) )
        return false;

    TQFile::remove( info );
    fileRemoved();
    return true;
}
コード例 #5
0
void SLAM_tumindoorImp::loadDataset(const string &path)
{
    train.push_back(vector< Ptr<Object> >());
    test.push_back(vector< Ptr<Object> >());
    validation.push_back(vector< Ptr<Object> >());

    string infoPath(path + "info/");

    // get info map name, .csv should be only one such file in folder
    string csvName;
    vector<string> infoNames;
    getDirList(infoPath, infoNames);
    for (vector<string>::iterator it=infoNames.begin(); it!=infoNames.end(); ++it)
    {
        string &name = *it;
        if (name.length()>3 && name.substr( name.length()-4, 4 )==".csv")
        {
            if (csvName.length()==0)
            {
                csvName = name;
            } else
            {
                printf("more than one .csv file in info folder\n");
                return;
            }
        }
    }
    if (csvName.length()==0)
    {
        printf("didn't find .csv file in info folder\n");
        return;
    }

    ifstream infile((infoPath + csvName).c_str());
    string line;
    while (getline(infile, line))
    {
        vector<string> elems;
        split(line, elems, ';');

        Ptr<SLAM_tumindoorObj> curr(new SLAM_tumindoorObj);

        curr->name = elems[0];
        if (curr->name.substr(0, strlen("dslr_left")) == "dslr_left")
        {
            curr->type = LEFT;
        } else
        if (curr->name.substr(0, strlen("dslr_right")) == "dslr_right")
        {
            curr->type = RIGHT;
        } else
        {
            curr->type = LADYBUG;
        }

        for (unsigned int i=0; i<4; ++i)
        {
            for (unsigned int j=0; j<4; ++j)
            {
                curr->transformMat(i, j) = atof(elems[1 + j + i*4].c_str());
            }
        }

        train.back().push_back(curr);
    }
}
コード例 #6
0
ファイル: trashimpl.cpp プロジェクト: Fat-Zer/tdebase
bool TrashImpl::createInfo( const TQString& origPath, int& trashId, TQString& fileId )
{
    kdDebug() << k_funcinfo << origPath << endl;
    // Check source
    const TQCString origPath_c( TQFile::encodeName( origPath ) );
    KDE_struct_stat buff_src;
    if ( KDE_lstat( origPath_c.data(), &buff_src ) == -1 ) {
        if ( errno == EACCES )
           error( TDEIO::ERR_ACCESS_DENIED, origPath );
        else
           error( TDEIO::ERR_DOES_NOT_EXIST, origPath );
        return false;
    }

    // Choose destination trash
    trashId = findTrashDirectory( origPath );
    if ( trashId < 0 ) {
        kdWarning() << "OUCH - internal error, TrashImpl::findTrashDirectory returned " << trashId << endl;
        return false; // ### error() needed?
    }
    kdDebug() << k_funcinfo << "trashing to " << trashId << endl;

    // Grab original filename
    KURL url;
    url.setPath( origPath );
    const TQString origFileName = url.fileName();

    // Make destination file in info/
    url.setPath( infoPath( trashId, origFileName ) ); // we first try with origFileName
    KURL baseDirectory;
    baseDirectory.setPath( url.directory() );
    // Here we need to use O_EXCL to avoid race conditions with other tdeioslave processes
    int fd = 0;
    do {
        kdDebug() << k_funcinfo << "trying to create " << url.path()  << endl;
        fd = ::open( TQFile::encodeName( url.path() ), O_WRONLY | O_CREAT | O_EXCL, 0600 );
        if ( fd < 0 ) {
            if ( errno == EEXIST ) {
                url.setFileName( TDEIO::RenameDlg::suggestName( baseDirectory, url.fileName() ) );
                // and try again on the next iteration
            } else {
                error( TDEIO::ERR_COULD_NOT_WRITE, url.path() );
                return false;
            }
        }
    } while ( fd < 0 );
    const TQString infoPath = url.path();
    fileId = url.fileName();
    Q_ASSERT( fileId.endsWith( ".trashinfo" ) );
    fileId.truncate( fileId.length() - 10 ); // remove .trashinfo from fileId

    FILE* file = ::fdopen( fd, "w" );
    if ( !file ) { // can't see how this would happen
        error( TDEIO::ERR_COULD_NOT_WRITE, infoPath );
        return false;
    }

    // Contents of the info file. We could use KSimpleConfig, but that would
    // mean closing and reopening fd, i.e. opening a race condition...
    TQCString info = "[Trash Info]\n";
    info += "Path=";
    // Escape filenames according to the way they are encoded on the filesystem
    // All this to basically get back to the raw 8-bit representation of the filename...
    if ( trashId == 0 ) // home trash: absolute path
        info += KURL::encode_string( origPath, m_mibEnum ).latin1();
    else
        info += KURL::encode_string( makeRelativePath( topDirectoryPath( trashId ), origPath ), m_mibEnum ).latin1();
    info += "\n";
    info += "DeletionDate=";
    info += TQDateTime::currentDateTime().toString( Qt::ISODate ).latin1();
    info += "\n";
    size_t sz = info.size() - 1; // avoid trailing 0 from QCString

    size_t written = ::fwrite(info.data(), 1, sz, file);
    if ( written != sz ) {
        ::fclose( file );
        TQFile::remove( infoPath );
        error( TDEIO::ERR_DISK_FULL, infoPath );
        return false;
    }

    ::fclose( file );

    kdDebug() << k_funcinfo << "info file created in trashId=" << trashId << " : " << fileId << endl;
    return true;
}