none
FIle Movement from Network Drive to Local RRS feed

  • Question

  • Hi Team,
    I am facing an issue with my windows service application.
    >> What it does is moves an Image file from "Network Drive" to "Local Drive"
    >> It uses windows API "MoveFileEx" to move the file
    >> It performs inside a thread

    >> After a long time (2, 3, days)  the thread got hanged

    >> After the analysis it confirm that "MoveFileEx" API never returns

    Tried to terminate the thread and it fails.

    Code;

        try
        {
            // validate the file
            HANDLE hFindFile = INVALID_HANDLE_VALUE;
            WIN32_FIND_DATA FindFileData;
            hFindFile        = ::FindFirstFile( tstrSourceFile.c_str(), &FindFileData );
            if( INVALID_HANDLE_VALUE == hFindFile )
            {
                DWORD dwErrorCode = ::GetLastError();
                m_pLogger->LogApp( WARNING, _T("CTracoRSSCore::MoveFile: File not found %s , GetLastError: %d"), tstrSourceFile.c_str(), dwErrorCode );
                return false;
            }
            ::FindClose( hFindFile );
            m_pLogger->LogDbg( EVENT_STATUS, _T("CTracoRSSCore::MoveFile: File Exists %s"), tstrSourceFile.c_str() );

            if( FALSE == ::MoveFileEx(tstrSourceFile.c_str(), tstrDestPath.c_str(), MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING) )
            {
                m_pLogger->LogDbg( EVENT_STATUS, _T("CTracoRSSCore::MoveFile: Attempt 1 failed to move %s"), tstrSourceFile.c_str() );
                DWORD dwErrorCode = ::GetLastError();
                if( ERROR_ACCESS_DENIED == dwErrorCode )
                {
                    ::SetFileAttributes( tstrSourceFile.c_str(), FILE_ATTRIBUTE_NORMAL );
                    if( FALSE == ::MoveFileEx(tstrSourceFile.c_str(), tstrDestPath.c_str(), MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING) )
                    {
                        m_pLogger->LogApp( WARNING, _T("CTracoRSSCore::MoveFile: Failed to Move file %s"), tstrSourceFile.c_str() );
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
                else if( ERROR_PATH_NOT_FOUND == dwErrorCode )
                {
                    m_pLogger->LogApp( WARNING, _T("CTracoRSSCore::MoveFile: Path Not Found %s"), tstrDestPath.c_str() );
                    return false;
                }
                else if( ERROR_ALREADY_EXISTS == dwErrorCode )
                {
                    m_pLogger->LogApp( WARNING, _T("CTracoRSSCore::MoveFile: File Already Exists %s"), tstrDestPath.c_str() );
                    return false;
                }
                m_pLogger->LogApp( WARNING, _T("CTracoRSSCore::MoveFile: Failed to Move file %s, GetLastError: %d"), tstrSourceFile.c_str(), dwErrorCode );
                return false;
            }
            m_pLogger->LogDbg( EVENT_STATUS, _T("CTracoRSSCore::MoveFile: File %s Moved to %s"), tstrSourceFile.c_str(), tstrDestPath.c_str() );
            return true;    // File moved
        }

    Monday, June 22, 2015 6:40 AM