Changeset 1540

Show
Ignore:
Timestamp:
07/20/05 05:50:38 (3 years ago)
Author:
madcat
Message:

Closes tickets #28 and #31 (endless loops when shared files are deleted)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • hydranode/hncore/src/sharedfile.cpp

    r1501 r1540  
    483483        } 
    484484 
     485        // first try to open, 'cos if the file doesn't exist, there's no point 
     486        // in the below modification date checks either 
     487        int fd = open( 
     488                getPath().native_file_string().c_str(), 
     489                O_RDONLY|O_LARGEFILE|O_BINARY 
     490        ); 
     491 
     492        if (fd == -1) {  
     493                if (m_locations.size()) { 
     494                        setLocation(m_locations.back().second); 
     495                        m_locations.pop_back(); 
     496                        return read(begin, end); 
     497                } 
     498                boost::format fmt("Unable to open shared file %s%s (reason: %s)"); 
     499                fmt % getName(); 
     500                if (isPartial()) { 
     501                        fmt % (" (loc=" + getPath().native_file_string() + ")"); 
     502                } else { 
     503                        fmt % ""; 
     504                } 
     505#ifdef WIN32 
     506                fmt % "unable to open file"; 
     507#else 
     508                fmt % strerror(errno); 
     509#endif 
     510                destroy(); // sorry, but if our file died, so shall we 
     511                throw std::runtime_error(fmt.str()); 
     512        } 
     513 
    485514        // check if modification date matches what we have on record 
    486515        // if not, and we'r partial file, just rehash completed parts; 
    487516        // otherwise, drop current metadata and rehash the file 
    488         if (m_metaData)
     517        if (m_metaData) try
    489518                uint32_t actual = Utils::getModDate(m_location); 
    490519                uint32_t stored = m_metaData->getModDate(); 
     
    504533                        throw std::runtime_error(fmt.str()); 
    505534                } 
    506         } 
    507  
    508         int fd = open( 
    509                 getPath().native_file_string().c_str(), 
    510                 O_RDONLY|O_LARGEFILE|O_BINARY 
    511         ); 
    512  
    513         if (fd == -1) {  
    514                 if (m_locations.size()) { 
    515                         setLocation(m_locations.back().second); 
    516                         m_locations.pop_back(); 
    517                         return read(begin, end); 
    518                 } 
    519                 boost::format fmt("Unable to open shared file %s%s (reason: %s)"); 
    520                 fmt % getName(); 
    521                 if (isPartial()) { 
    522                         fmt % (" (loc=" + getPath().native_file_string() + ")"); 
    523                 } else { 
    524                         fmt % ""; 
    525                 } 
    526 #ifdef WIN32 
    527                 fmt % "unable to open file"; 
    528 #else 
    529                 fmt % strerror(errno); 
    530 #endif 
    531                 destroy(); // sorry, but if our file died, so shall we 
    532                 throw std::runtime_error(fmt.str()); 
     535        } catch (...) { 
     536                close(fd); 
     537                throw; 
    533538        } 
    534539