Changeset 4123

Show
Ignore:
Timestamp:
10/30/08 06:38:25 (2 months ago)
Author:
markybob
Message:

lt 2879-storage cleanup and truncating files that are larger than they should be

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0.0_RC/libtorrent/src/storage.cpp

    r4018 r4123  
    506506                        if (dir != last_path) 
    507507                        { 
     508                                last_path = dir; 
    508509 
    509510#if defined(_WIN32) && defined(UNICODE) && BOOST_VERSION < 103400 
    510                                 last_path = dir; 
    511511                                if (!exists_win(last_path)) 
    512512                                        create_directories_win(last_path); 
    513513#elif TORRENT_USE_WPATH 
    514                                 last_path = dir; 
    515514                                fs::wpath wp = safe_convert(last_path.string()); 
    516515                                if (!exists(wp)) 
    517516                                        create_directories(wp); 
    518517#else 
    519                                 last_path = dir; 
    520518                                if (!exists(last_path)) 
    521519                                        create_directories(last_path); 
     
    523521                        } 
    524522 
    525                         // if the file is empty, just create it. But also make sure 
    526                         // the directory exists. 
    527                         if (file_iter->size == 0) 
    528                         { 
    529                                 boost::shared_ptr<file> f = m_pool.open_file(this 
    530                                         , m_save_path / file_iter->path, file::in | file::out, ec); 
    531                                 if (ec) 
    532                                 { 
    533                                         set_error(m_save_path / file_iter->path, ec); 
    534                                         return true; 
    535                                 } 
    536                                 continue; 
    537                         } 
    538  
    539523#ifndef BOOST_NO_EXCEPTIONS 
    540524                        try { 
    541525#endif 
    542                         // don't allocate files with priority 0 
    543                         int file_index = file_iter - files().begin(); 
    544                         if (allocate_files && (int(m_file_priority.size()) <= file_index 
    545                                 || m_file_priority[file_index] > 0)) 
     526 
     527#if TORRENT_USE_WPATH 
     528                        fs::wpath file_path = safe_convert(m_save_path / file_iter->path); 
     529#else 
     530                        fs::path file_path = m_save_path / file_iter->path; 
     531#endif 
     532                        // if the file is empty, just create it either way. 
     533                        // if the file already exists, but is larger than what 
     534                        // it's supposed to be, also truncate it 
     535                        if (allocate_files 
     536                                || file_iter->size == 0 
     537                                || (exists(file_path) && file_size(file_path) > file_iter->size)) 
    546538                        { 
    547539                                error_code ec; 
     
    22812273                                && m_storage->error() != error_code(ENOENT, get_posix_category())) 
    22822274#endif 
    2283                         { 
    2284                                 std::cerr << m_storage->error().message() << std::endl; 
    22852275                                return -1; 
    2286                         } 
    22872276                        return 1; 
    22882277                } 
  • trunk/libtorrent/src/storage.cpp

    r4018 r4123  
    506506                        if (dir != last_path) 
    507507                        { 
     508                                last_path = dir; 
    508509 
    509510#if defined(_WIN32) && defined(UNICODE) && BOOST_VERSION < 103400 
    510                                 last_path = dir; 
    511511                                if (!exists_win(last_path)) 
    512512                                        create_directories_win(last_path); 
    513513#elif TORRENT_USE_WPATH 
    514                                 last_path = dir; 
    515514                                fs::wpath wp = safe_convert(last_path.string()); 
    516515                                if (!exists(wp)) 
    517516                                        create_directories(wp); 
    518517#else 
    519                                 last_path = dir; 
    520518                                if (!exists(last_path)) 
    521519                                        create_directories(last_path); 
     
    523521                        } 
    524522 
    525                         // if the file is empty, just create it. But also make sure 
    526                         // the directory exists. 
    527                         if (file_iter->size == 0) 
    528                         { 
    529                                 boost::shared_ptr<file> f = m_pool.open_file(this 
    530                                         , m_save_path / file_iter->path, file::in | file::out, ec); 
    531                                 if (ec) 
    532                                 { 
    533                                         set_error(m_save_path / file_iter->path, ec); 
    534                                         return true; 
    535                                 } 
    536                                 continue; 
    537                         } 
    538  
    539523#ifndef BOOST_NO_EXCEPTIONS 
    540524                        try { 
    541525#endif 
    542                         // don't allocate files with priority 0 
    543                         int file_index = file_iter - files().begin(); 
    544                         if (allocate_files && (int(m_file_priority.size()) <= file_index 
    545                                 || m_file_priority[file_index] > 0)) 
     526 
     527#if TORRENT_USE_WPATH 
     528                        fs::wpath file_path = safe_convert(m_save_path / file_iter->path); 
     529#else 
     530                        fs::path file_path = m_save_path / file_iter->path; 
     531#endif 
     532                        // if the file is empty, just create it either way. 
     533                        // if the file already exists, but is larger than what 
     534                        // it's supposed to be, also truncate it 
     535                        if (allocate_files 
     536                                || file_iter->size == 0 
     537                                || (exists(file_path) && file_size(file_path) > file_iter->size)) 
    546538                        { 
    547539                                error_code ec; 
     
    22812273                                && m_storage->error() != error_code(ENOENT, get_posix_category())) 
    22822274#endif 
    2283                         { 
    2284                                 std::cerr << m_storage->error().message() << std::endl; 
    22852275                                return -1; 
    2286                         } 
    22872276                        return 1; 
    22882277                }