Changeset 2992


Ignore:
Timestamp:
28/08/2011 20:07:17 (9 months ago)
Author:
chris
Message:

Use "more standard" Windows API functions FindFirstFileW and FindNextFileW
for directory enumeration instead of _wfindfirst and _wfindnext.

Ignore reparse points when enumerating directories to avoid infinite loops.

Convert VSS paths back to real paths when notifying users about backup
progress.

Location:
box/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp

    r2983 r2992  
    1919 
    2020#include "autogen_BackupProtocol.h" 
     21#include "autogen_ClientException.h" 
    2122#include "Archive.h" 
    2223#include "BackupClientContext.h" 
     
    102103} 
    103104 
     105std::string BackupClientDirectoryRecord::ConvertVssPathToRealPath( 
     106        const std::string &rVssPath, 
     107        const Location& rBackupLocation) 
     108{ 
     109#ifdef ENABLE_VSS 
     110        if (rBackupLocation.mIsSnapshotCreated && 
     111                rVssPath.substr(0, rBackupLocation.mSnapshotPath.length()) == 
     112                rBackupLocation.mSnapshotPath) 
     113        { 
     114                return rBackupLocation.mPath + 
     115                        rVssPath.substr(rBackupLocation.mSnapshotPath.length()); 
     116        } 
     117#endif 
     118 
     119        return rVssPath; 
     120} 
     121 
    104122// -------------------------------------------------------------------------- 
    105123// 
     
    119137        const std::string &rLocalPath, 
    120138        const std::string &rRemotePath, 
     139        const Location& rBackupLocation, 
    121140        bool ThisDirHasJustBeenCreated) 
    122141{ 
     
    164183                        // deletion will be noticed, deleted from server, 
    165184                        // and this object deleted. 
    166                         rNotifier.NotifyDirStatFailed(this, rLocalPath, 
     185                        rNotifier.NotifyDirStatFailed(this, 
     186                                ConvertVssPathToRealPath(rLocalPath, rBackupLocation), 
    167187                                strerror(errno)); 
    168188                        return; 
     
    213233                // Report the error (logs and  
    214234                // eventual email to administrator) 
    215                 rNotifier.NotifyFileStatFailed(this, rLocalPath, 
     235                rNotifier.NotifyFileStatFailed(this,  
     236                        ConvertVssPathToRealPath(rLocalPath, rBackupLocation), 
    216237                        strerror(errno)); 
    217238                 
    218239                // FIXME move to NotifyFileStatFailed() 
    219                 SetErrorWhenReadingFilesystemObject(rParams,  
    220                         rLocalPath.c_str()); 
     240                SetErrorWhenReadingFilesystemObject(rParams, rLocalPath); 
    221241                 
    222242                // This shouldn't happen, so we'd better not continue 
     
    230250                try 
    231251                { 
    232                         rNotifier.NotifyScanDirectory(this, rLocalPath); 
     252                        rNotifier.NotifyScanDirectory(this, 
     253                                ConvertVssPathToRealPath(rLocalPath, rBackupLocation)); 
    233254 
    234255                        dirHandle = ::opendir(rLocalPath.c_str()); 
     
    240261                                { 
    241262                                        rNotifier.NotifyDirListFailed(this, 
    242                                                 rLocalPath, "Access denied"); 
     263                                                ConvertVssPathToRealPath(rLocalPath, rBackupLocation), 
     264                                                "Access denied"); 
    243265                                } 
    244266                                else 
    245267                                { 
    246268                                        rNotifier.NotifyDirListFailed(this,  
    247                                                 rLocalPath, strerror(errno)); 
     269                                                ConvertVssPathToRealPath(rLocalPath, rBackupLocation), 
     270                                                strerror(errno)); 
    248271                                } 
    249272                                 
    250273                                // Report the error (logs and eventual email 
    251274                                // to administrator) 
    252                                 SetErrorWhenReadingFilesystemObject(rParams, 
    253                                         rLocalPath.c_str()); 
     275                                SetErrorWhenReadingFilesystemObject(rParams, rLocalPath); 
    254276                                // Ignore this directory for now. 
    255277                                return; 
     
    298320                                // which would normally contain DT_REG,  
    299321                                // DT_DIR, etc, but we only use it here and  
    300                                 // prefer S_IFREG, S_IFDIR... 
    301                                 int type = en->d_type; 
    302                                 #else 
     322                                // prefer to have the full file attributes. 
     323                                int type; 
     324                                if (en->d_type & FILE_ATTRIBUTE_DIRECTORY) 
     325                                { 
     326                                        type = S_IFDIR; 
     327                                } 
     328                                else 
     329                                { 
     330                                        type = S_IFREG; 
     331                                } 
     332 
     333                                #else // !WIN32 
     334 
    303335                                if(EMU_LSTAT(filename.c_str(), &file_st) != 0) 
    304336                                { 
     
    315347                                                // FIXME move to 
    316348                                                // NotifyFileStatFailed() 
    317                                                 SetErrorWhenReadingFilesystemObject( 
    318                                                         rParams, filename.c_str()); 
     349                                                SetErrorWhenReadingFilesystemObject(rParams, filename); 
    319350                                        } 
    320351 
     
    348379                                                mSuppressMultipleLinksWarning = true; 
    349380                                        } 
    350                                         SetErrorWhenReadingFilesystemObject( 
    351                                                 rParams, filename.c_str()); 
     381                                        SetErrorWhenReadingFilesystemObject(rParams, filename); 
    352382                                } 
    353383 
     
    381411                                        if(rParams.mrContext.ExcludeFile(filename)) 
    382412                                        { 
    383                                                 rNotifier.NotifyFileExcluded( 
    384                                                                 this,  
    385                                                                 filename); 
     413                                                rNotifier.NotifyFileExcluded(this, 
     414                                                        ConvertVssPathToRealPath(filename, rBackupLocation)); 
    386415 
    387416                                                // Next item! 
     
    399428                                        if(rParams.mrContext.ExcludeDir(filename)) 
    400429                                        { 
    401                                                 rNotifier.NotifyDirExcluded( 
    402                                                                 this,  
    403                                                                 filename); 
     430                                                rNotifier.NotifyDirExcluded(this, 
     431                                                        ConvertVssPathToRealPath(filename, rBackupLocation)); 
    404432 
    405433                                                // Next item! 
    406434                                                continue; 
    407435                                        } 
     436 
     437                                        #ifdef WIN32 
     438                                        // exclude reparse points, as Application Data points to the 
     439                                        // parent directory under Vista and later, and causes an 
     440                                        // infinite loop:  
     441                                        // http://social.msdn.microsoft.com/forums/en-US/windowscompatibility/thread/05d14368-25dd-41c8-bdba-5590bf762a68/ 
     442                                        if (en->d_type & FILE_ATTRIBUTE_REPARSE_POINT) 
     443                                        { 
     444                                                rNotifier.NotifyMountPointSkipped(this, 
     445                                                        ConvertVssPathToRealPath(filename, rBackupLocation)); 
     446                                                continue; 
     447                                        } 
     448                                        #endif 
    408449 
    409450                                        // Store on list 
     
    423464                                        else if(rParams.mrContext.ExcludeFile(filename)) 
    424465                                        { 
    425                                                 rNotifier.NotifyFileExcluded( 
    426                                                                 this,  
    427                                                                 filename); 
     466                                                rNotifier.NotifyFileExcluded(this,  
     467                                                        ConvertVssPathToRealPath(filename, rBackupLocation)); 
    428468                                        } 
    429469                                        else 
    430470                                        { 
    431                                                 rNotifier.NotifyUnsupportedFileType( 
    432                                                                 this, filename); 
    433                                                 SetErrorWhenReadingFilesystemObject( 
    434                                                         rParams, filename.c_str()); 
     471                                                rNotifier.NotifyUnsupportedFileType(this,  
     472                                                        ConvertVssPathToRealPath(filename, rBackupLocation)); 
     473                                                SetErrorWhenReadingFilesystemObject(rParams, 
     474                                                        ConvertVssPathToRealPath(filename, rBackupLocation)); 
    435475                                        } 
    436476 
     
    447487                                { 
    448488                                        rNotifier.NotifyFileStatFailed(this,  
    449                                                         filename,  
     489                                                        ConvertVssPathToRealPath(filename, rBackupLocation), 
    450490                                                        strerror(errno)); 
    451491                                         
    452492                                        // Report the error (logs and  
    453493                                        // eventual email to administrator) 
    454                                         SetErrorWhenReadingFilesystemObject( 
    455                                                 rParams, filename.c_str()); 
     494                                        SetErrorWhenReadingFilesystemObject(rParams, filename); 
    456495 
    457496                                        // Ignore this entry for now. 
     
    462501                                { 
    463502                                        rNotifier.NotifyMountPointSkipped(this,  
    464                                                         filename); 
     503                                                ConvertVssPathToRealPath(filename, rBackupLocation)); 
    465504                                        continue; 
    466505                                } 
     
    482521                                        if(!rParams.mHaveLoggedWarningAboutFutureFileTimes) 
    483522                                        { 
    484                                                 rNotifier.NotifyFileModifiedInFuture( 
    485                                                         this, filename); 
     523                                                rNotifier.NotifyFileModifiedInFuture(this, 
     524                                                        ConvertVssPathToRealPath(filename, rBackupLocation)); 
    486525                                                rParams.mHaveLoggedWarningAboutFutureFileTimes = true; 
    487526                                        } 
     
    557596                // Do the directory reading 
    558597                bool updateCompleteSuccess = UpdateItems(rParams, rLocalPath, 
    559                         rRemotePath, pdirOnStore, entriesLeftOver, files, dirs); 
     598                        rRemotePath, rBackupLocation, pdirOnStore, entriesLeftOver, files, dirs); 
    560599                 
    561600                // LAST THING! (think exception safety) 
     
    700739        const std::string &rLocalPath, 
    701740        const std::string &rRemotePath, 
     741        const Location& rBackupLocation, 
    702742        BackupStoreDirectory *pDirOnStore, 
    703743        std::vector<BackupStoreDirectory::Entry *> &rEntriesLeftOver, 
     
    755795                                // Report the error (logs and  
    756796                                // eventual email to administrator) 
    757                                 SetErrorWhenReadingFilesystemObject(rParams,  
    758                                         filename.c_str()); 
     797                                SetErrorWhenReadingFilesystemObject(rParams, filename); 
    759798 
    760799                                // Ignore this entry for now. 
     
    10611100                                        allUpdatedSuccessfully = false; 
    10621101                                        // Log it. 
    1063                                         SetErrorWhenReadingFilesystemObject(rParams, filename.c_str()); 
    1064                                         rNotifier.NotifyFileUploadException( 
    1065                                                 this, filename, e); 
     1102                                        SetErrorWhenReadingFilesystemObject(rParams, filename); 
     1103                                        rNotifier.NotifyFileUploadException(this, filename, e); 
    10661104                                } 
    10671105 
     
    10821120                        { 
    10831121                                rNotifier.NotifyFileSkippedServerFull(this, 
    1084                                         filename); 
     1122                                        ConvertVssPathToRealPath(filename, rBackupLocation)); 
    10851123                        } 
    10861124                } 
     
    14211459                { 
    14221460                        // Sync this sub directory too 
    1423                         psubDirRecord->SyncDirectory(rParams, mObjectID, 
    1424                                 dirname, rRemotePath + "/" + *d, 
     1461                        psubDirRecord->SyncDirectory(rParams, mObjectID, dirname, 
     1462                                rRemotePath + "/" + *d, rBackupLocation, 
    14251463                                haveJustCreatedDirOnServer); 
    14261464                } 
     
    17321770// 
    17331771// -------------------------------------------------------------------------- 
    1734 void BackupClientDirectoryRecord::SetErrorWhenReadingFilesystemObject(BackupClientDirectoryRecord::SyncParams &rParams, const char *Filename) 
     1772void BackupClientDirectoryRecord::SetErrorWhenReadingFilesystemObject( 
     1773        BackupClientDirectoryRecord::SyncParams &rParams, 
     1774        const std::string& rFilename) 
    17351775{ 
    17361776        // Zero hash, so it gets synced properly next time round. 
     
    19662006        } 
    19672007} 
     2008 
     2009// -------------------------------------------------------------------------- 
     2010// 
     2011// Function 
     2012//              Name:    Location::Location() 
     2013//              Purpose: Constructor 
     2014//              Created: 11/11/03 
     2015// 
     2016// -------------------------------------------------------------------------- 
     2017Location::Location() 
     2018        : mIDMapIndex(0), 
     2019          mpExcludeFiles(0), 
     2020          mpExcludeDirs(0) 
     2021{ 
     2022} 
     2023 
     2024// -------------------------------------------------------------------------- 
     2025// 
     2026// Function 
     2027//              Name:    Location::~Location() 
     2028//              Purpose: Destructor 
     2029//              Created: 11/11/03 
     2030// 
     2031// -------------------------------------------------------------------------- 
     2032Location::~Location() 
     2033{ 
     2034        // Clean up exclude locations 
     2035        if(mpExcludeDirs != 0) 
     2036        { 
     2037                delete mpExcludeDirs; 
     2038                mpExcludeDirs = 0; 
     2039        } 
     2040        if(mpExcludeFiles != 0) 
     2041        { 
     2042                delete mpExcludeFiles; 
     2043                mpExcludeFiles = 0; 
     2044        } 
     2045} 
     2046 
     2047// -------------------------------------------------------------------------- 
     2048// 
     2049// Function 
     2050//              Name:    Location::Serialize(Archive & rArchive) 
     2051//              Purpose: Serializes this object instance into a stream of bytes, 
     2052//               using an Archive abstraction. 
     2053// 
     2054//              Created: 2005/04/11 
     2055// 
     2056// -------------------------------------------------------------------------- 
     2057void Location::Serialize(Archive & rArchive) const 
     2058{ 
     2059        // 
     2060        // 
     2061        // 
     2062        rArchive.Write(mName); 
     2063        rArchive.Write(mPath); 
     2064        rArchive.Write(mIDMapIndex); 
     2065 
     2066        // 
     2067        // 
     2068        // 
     2069        if(mpDirectoryRecord.get() == NULL) 
     2070        { 
     2071                int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_NOOP; 
     2072                rArchive.Write(aMagicMarker); 
     2073        } 
     2074        else 
     2075        { 
     2076                int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_RECURSE; // be explicit about whether recursion follows 
     2077                rArchive.Write(aMagicMarker); 
     2078 
     2079                mpDirectoryRecord->Serialize(rArchive); 
     2080        } 
     2081 
     2082        // 
     2083        // 
     2084        // 
     2085        if(!mpExcludeFiles) 
     2086        { 
     2087                int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_NOOP; 
     2088                rArchive.Write(aMagicMarker); 
     2089        } 
     2090        else 
     2091        { 
     2092                int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_RECURSE; // be explicit about whether recursion follows 
     2093                rArchive.Write(aMagicMarker); 
     2094 
     2095                mpExcludeFiles->Serialize(rArchive); 
     2096        } 
     2097 
     2098        // 
     2099        // 
     2100        // 
     2101        if(!mpExcludeDirs) 
     2102        { 
     2103                int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_NOOP; 
     2104                rArchive.Write(aMagicMarker); 
     2105        } 
     2106        else 
     2107        { 
     2108                int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_RECURSE; // be explicit about whether recursion follows 
     2109                rArchive.Write(aMagicMarker); 
     2110 
     2111                mpExcludeDirs->Serialize(rArchive); 
     2112        } 
     2113} 
     2114 
     2115// -------------------------------------------------------------------------- 
     2116// 
     2117// Function 
     2118//              Name:    Location::Deserialize(Archive & rArchive) 
     2119//              Purpose: Deserializes this object instance from a stream of bytes, using an Archive abstraction. 
     2120// 
     2121//              Created: 2005/04/11 
     2122// 
     2123// -------------------------------------------------------------------------- 
     2124void Location::Deserialize(Archive &rArchive) 
     2125{ 
     2126        // 
     2127        // 
     2128        // 
     2129        mpDirectoryRecord.reset(NULL); 
     2130        if(mpExcludeFiles) 
     2131        { 
     2132                delete mpExcludeFiles; 
     2133                mpExcludeFiles = NULL; 
     2134        } 
     2135        if(mpExcludeDirs) 
     2136        { 
     2137                delete mpExcludeDirs; 
     2138                mpExcludeDirs = NULL; 
     2139        } 
     2140 
     2141        // 
     2142        // 
     2143        // 
     2144        rArchive.Read(mName); 
     2145        rArchive.Read(mPath); 
     2146        rArchive.Read(mIDMapIndex); 
     2147 
     2148        // 
     2149        // 
     2150        // 
     2151        int64_t aMagicMarker = 0; 
     2152        rArchive.Read(aMagicMarker); 
     2153 
     2154        if(aMagicMarker == ARCHIVE_MAGIC_VALUE_NOOP) 
     2155        { 
     2156                // NOOP 
     2157        } 
     2158        else if(aMagicMarker == ARCHIVE_MAGIC_VALUE_RECURSE) 
     2159        { 
     2160                BackupClientDirectoryRecord *pSubRecord = new BackupClientDirectoryRecord(0, ""); 
     2161                if(!pSubRecord) 
     2162                { 
     2163                        throw std::bad_alloc(); 
     2164                } 
     2165 
     2166                mpDirectoryRecord.reset(pSubRecord); 
     2167                mpDirectoryRecord->Deserialize(rArchive); 
     2168        } 
     2169        else 
     2170        { 
     2171                // there is something going on here 
     2172                THROW_EXCEPTION(ClientException, CorruptStoreObjectInfoFile); 
     2173        } 
     2174 
     2175        // 
     2176        // 
     2177        // 
     2178        rArchive.Read(aMagicMarker); 
     2179 
     2180        if(aMagicMarker == ARCHIVE_MAGIC_VALUE_NOOP) 
     2181        { 
     2182                // NOOP 
     2183        } 
     2184        else if(aMagicMarker == ARCHIVE_MAGIC_VALUE_RECURSE) 
     2185        { 
     2186                mpExcludeFiles = new ExcludeList; 
     2187                if(!mpExcludeFiles) 
     2188                { 
     2189                        throw std::bad_alloc(); 
     2190                } 
     2191 
     2192                mpExcludeFiles->Deserialize(rArchive); 
     2193        } 
     2194        else 
     2195        { 
     2196                // there is something going on here 
     2197                THROW_EXCEPTION(ClientException, CorruptStoreObjectInfoFile); 
     2198        } 
     2199 
     2200        // 
     2201        // 
     2202        // 
     2203        rArchive.Read(aMagicMarker); 
     2204 
     2205        if(aMagicMarker == ARCHIVE_MAGIC_VALUE_NOOP) 
     2206        { 
     2207                // NOOP 
     2208        } 
     2209        else if(aMagicMarker == ARCHIVE_MAGIC_VALUE_RECURSE) 
     2210        { 
     2211                mpExcludeDirs = new ExcludeList; 
     2212                if(!mpExcludeDirs) 
     2213                { 
     2214                        throw std::bad_alloc(); 
     2215                } 
     2216 
     2217                mpExcludeDirs->Deserialize(rArchive); 
     2218        } 
     2219        else 
     2220        { 
     2221                // there is something going on here 
     2222                THROW_EXCEPTION(ClientException, CorruptStoreObjectInfoFile); 
     2223        } 
     2224} 
  • box/trunk/bin/bbackupd/BackupClientDirectoryRecord.h

    r2977 r2992  
    2222#include "RunStatusProvider.h" 
    2323 
     24#ifdef ENABLE_VSS 
     25#       include <comdef.h> 
     26#       include <Vss.h> 
     27#       include <VsWriter.h> 
     28#       include <VsBackup.h> 
     29#endif 
     30 
    2431class Archive; 
    2532class BackupClientContext; 
    2633class BackupDaemon; 
     34class ExcludeList; 
     35class Location; 
    2736 
    2837// -------------------------------------------------------------------------- 
     
    126135                const std::string &rLocalPath, 
    127136                const std::string &rRemotePath, 
     137                const Location& rBackupLocation, 
    128138                bool ThisDirHasJustBeenCreated = false); 
     139 
     140        std::string ConvertVssPathToRealPath(const std::string &rVssPath, 
     141                const Location& rBackupLocation); 
    129142 
    130143private: 
     
    136149        bool UpdateItems(SyncParams &rParams, const std::string &rLocalPath, 
    137150                const std::string &rRemotePath, 
     151                const Location& rBackupLocation, 
    138152                BackupStoreDirectory *pDirOnStore, 
    139153                std::vector<BackupStoreDirectory::Entry *> &rEntriesLeftOver, 
     
    146160                box_time_t AttributesHash, bool NoPreviousVersionOnServer); 
    147161        void SetErrorWhenReadingFilesystemObject(SyncParams &rParams, 
    148                 const char *Filename); 
     162                const std::string& rFilename); 
    149163        void RemoveDirectoryInPlaceOfFile(SyncParams &rParams, 
    150164                BackupStoreDirectory* pDirOnStore, 
     
    169183}; 
    170184 
     185class Location 
     186{ 
     187public: 
     188        Location(); 
     189        ~Location(); 
     190 
     191        void Deserialize(Archive & rArchive); 
     192        void Serialize(Archive & rArchive) const; 
     193private: 
     194        Location(const Location &);     // copy not allowed 
     195        Location &operator=(const Location &); 
     196public: 
     197        std::string mName; 
     198        std::string mPath; 
     199        std::auto_ptr<BackupClientDirectoryRecord> mpDirectoryRecord; 
     200        int mIDMapIndex; 
     201        ExcludeList *mpExcludeFiles; 
     202        ExcludeList *mpExcludeDirs; 
     203 
     204#ifdef ENABLE_VSS 
     205        bool mIsSnapshotCreated; 
     206        VSS_ID mSnapshotVolumeId; 
     207        std::string mSnapshotPath; 
     208#endif 
     209}; 
     210 
    171211#endif // BACKUPCLIENTDIRECTORYRECORD__H 
    172212 
  • box/trunk/bin/bbackupd/BackupDaemon.cpp

    r2986 r2992  
    10151015                (*i)->mpDirectoryRecord->SyncDirectory(params, 
    10161016                        BackupProtocolListDirectory::RootDirectory, 
    1017                         locationPath, std::string("/") + (*i)->mName); 
     1017                        locationPath, std::string("/") + (*i)->mName, **i); 
    10181018 
    10191019                // Unset exclude lists (just in case) 
     
    29482948// 
    29492949// Function 
    2950 //              Name:    BackupDaemon::Location::Location() 
    2951 //              Purpose: Constructor 
    2952 //              Created: 11/11/03 
    2953 // 
    2954 // -------------------------------------------------------------------------- 
    2955 BackupDaemon::Location::Location() 
    2956         : mIDMapIndex(0), 
    2957           mpExcludeFiles(0), 
    2958           mpExcludeDirs(0) 
    2959 { 
    2960 } 
    2961  
    2962 // -------------------------------------------------------------------------- 
    2963 // 
    2964 // Function 
    2965 //              Name:    BackupDaemon::Location::~Location() 
    2966 //              Purpose: Destructor 
    2967 //              Created: 11/11/03 
    2968 // 
    2969 // -------------------------------------------------------------------------- 
    2970 BackupDaemon::Location::~Location() 
    2971 { 
    2972         // Clean up exclude locations 
    2973         if(mpExcludeDirs != 0) 
    2974         { 
    2975                 delete mpExcludeDirs; 
    2976                 mpExcludeDirs = 0; 
    2977         } 
    2978         if(mpExcludeFiles != 0) 
    2979         { 
    2980                 delete mpExcludeFiles; 
    2981                 mpExcludeFiles = 0; 
    2982         } 
    2983 } 
    2984  
    2985 // -------------------------------------------------------------------------- 
    2986 // 
    2987 // Function 
    2988 //              Name:    BackupDaemon::Location::Deserialize(Archive & rArchive) 
    2989 //              Purpose: Deserializes this object instance from a stream of bytes, using an Archive abstraction. 
    2990 // 
    2991 //              Created: 2005/04/11 
    2992 // 
    2993 // -------------------------------------------------------------------------- 
    2994 void BackupDaemon::Location::Deserialize(Archive &rArchive) 
    2995 { 
    2996         // 
    2997         // 
    2998         // 
    2999         mpDirectoryRecord.reset(NULL); 
    3000         if(mpExcludeFiles) 
    3001         { 
    3002                 delete mpExcludeFiles; 
    3003                 mpExcludeFiles = NULL; 
    3004         } 
    3005         if(mpExcludeDirs) 
    3006         { 
    3007                 delete mpExcludeDirs; 
    3008                 mpExcludeDirs = NULL; 
    3009         } 
    3010  
    3011         // 
    3012         // 
    3013         // 
    3014         rArchive.Read(mName); 
    3015         rArchive.Read(mPath); 
    3016         rArchive.Read(mIDMapIndex); 
    3017  
    3018         // 
    3019         // 
    3020         // 
    3021         int64_t aMagicMarker = 0; 
    3022         rArchive.Read(aMagicMarker); 
    3023  
    3024         if(aMagicMarker == ARCHIVE_MAGIC_VALUE_NOOP) 
    3025         { 
    3026                 // NOOP 
    3027         } 
    3028         else if(aMagicMarker == ARCHIVE_MAGIC_VALUE_RECURSE) 
    3029         { 
    3030                 BackupClientDirectoryRecord *pSubRecord = new BackupClientDirectoryRecord(0, ""); 
    3031                 if(!pSubRecord) 
    3032                 { 
    3033                         throw std::bad_alloc(); 
    3034                 } 
    3035  
    3036                 mpDirectoryRecord.reset(pSubRecord); 
    3037                 mpDirectoryRecord->Deserialize(rArchive); 
    3038         } 
    3039         else 
    3040         { 
    3041                 // there is something going on here 
    3042                 THROW_EXCEPTION(ClientException, CorruptStoreObjectInfoFile); 
    3043         } 
    3044  
    3045         // 
    3046         // 
    3047         // 
    3048         rArchive.Read(aMagicMarker); 
    3049  
    3050         if(aMagicMarker == ARCHIVE_MAGIC_VALUE_NOOP) 
    3051         { 
    3052                 // NOOP 
    3053         } 
    3054         else if(aMagicMarker == ARCHIVE_MAGIC_VALUE_RECURSE) 
    3055         { 
    3056                 mpExcludeFiles = new ExcludeList; 
    3057                 if(!mpExcludeFiles) 
    3058                 { 
    3059                         throw std::bad_alloc(); 
    3060                 } 
    3061  
    3062                 mpExcludeFiles->Deserialize(rArchive); 
    3063         } 
    3064         else 
    3065         { 
    3066                 // there is something going on here 
    3067                 THROW_EXCEPTION(ClientException, CorruptStoreObjectInfoFile); 
    3068         } 
    3069  
    3070         // 
    3071         // 
    3072         // 
    3073         rArchive.Read(aMagicMarker); 
    3074  
    3075         if(aMagicMarker == ARCHIVE_MAGIC_VALUE_NOOP) 
    3076         { 
    3077                 // NOOP 
    3078         } 
    3079         else if(aMagicMarker == ARCHIVE_MAGIC_VALUE_RECURSE) 
    3080         { 
    3081                 mpExcludeDirs = new ExcludeList; 
    3082                 if(!mpExcludeDirs) 
    3083                 { 
    3084                         throw std::bad_alloc(); 
    3085                 } 
    3086  
    3087                 mpExcludeDirs->Deserialize(rArchive); 
    3088         } 
    3089         else 
    3090         { 
    3091                 // there is something going on here 
    3092                 THROW_EXCEPTION(ClientException, CorruptStoreObjectInfoFile); 
    3093         } 
    3094 } 
    3095  
    3096 // -------------------------------------------------------------------------- 
    3097 // 
    3098 // Function 
    3099 //              Name:    BackupDaemon::Location::Serialize(Archive & rArchive) 
    3100 //              Purpose: Serializes this object instance into a stream of bytes, using an Archive abstraction. 
    3101 // 
    3102 //              Created: 2005/04/11 
    3103 // 
    3104 // -------------------------------------------------------------------------- 
    3105 void BackupDaemon::Location::Serialize(Archive & rArchive) const 
    3106 { 
    3107         // 
    3108         // 
    3109         // 
    3110         rArchive.Write(mName); 
    3111         rArchive.Write(mPath); 
    3112         rArchive.Write(mIDMapIndex); 
    3113  
    3114         // 
    3115         // 
    3116         // 
    3117         if(mpDirectoryRecord.get() == NULL) 
    3118         { 
    3119                 int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_NOOP; 
    3120                 rArchive.Write(aMagicMarker); 
    3121         } 
    3122         else 
    3123         { 
    3124                 int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_RECURSE; // be explicit about whether recursion follows 
    3125                 rArchive.Write(aMagicMarker); 
    3126  
    3127                 mpDirectoryRecord->Serialize(rArchive); 
    3128         } 
    3129  
    3130         // 
    3131         // 
    3132         // 
    3133         if(!mpExcludeFiles) 
    3134         { 
    3135                 int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_NOOP; 
    3136                 rArchive.Write(aMagicMarker); 
    3137         } 
    3138         else 
    3139         { 
    3140                 int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_RECURSE; // be explicit about whether recursion follows 
    3141                 rArchive.Write(aMagicMarker); 
    3142  
    3143                 mpExcludeFiles->Serialize(rArchive); 
    3144         } 
    3145  
    3146         // 
    3147         // 
    3148         // 
    3149         if(!mpExcludeDirs) 
    3150         { 
    3151                 int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_NOOP; 
    3152                 rArchive.Write(aMagicMarker); 
    3153         } 
    3154         else 
    3155         { 
    3156                 int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_RECURSE; // be explicit about whether recursion follows 
    3157                 rArchive.Write(aMagicMarker); 
    3158  
    3159                 mpExcludeDirs->Serialize(rArchive); 
    3160         } 
    3161 } 
    3162  
    3163 // -------------------------------------------------------------------------- 
    3164 // 
    3165 // Function 
    31662950//              Name:    BackupDaemon::CommandSocketInfo::CommandSocketInfo() 
    31672951//              Purpose: Constructor 
  • box/trunk/bin/bbackupd/BackupDaemon.h

    r2983 r2992  
    158158 
    159159public: 
    160         class Location 
    161         { 
    162         public: 
    163                 Location(); 
    164                 ~Location(); 
    165  
    166                 void Deserialize(Archive & rArchive); 
    167                 void Serialize(Archive & rArchive) const; 
    168         private: 
    169                 Location(const Location &);     // copy not allowed 
    170                 Location &operator=(const Location &); 
    171         public: 
    172                 std::string mName; 
    173                 std::string mPath; 
    174                 std::auto_ptr<BackupClientDirectoryRecord> mpDirectoryRecord; 
    175                 int mIDMapIndex; 
    176                 ExcludeList *mpExcludeFiles; 
    177                 ExcludeList *mpExcludeDirs; 
    178  
    179 #ifdef ENABLE_VSS 
    180                 bool mIsSnapshotCreated; 
    181                 VSS_ID mSnapshotVolumeId; 
    182                 std::string mSnapshotPath; 
    183 #endif 
    184         }; 
    185          
    186160        typedef const std::vector<Location *> Locations; 
    187161        Locations GetLocations() { return mLocations; } 
  • box/trunk/lib/win32/emu.cpp

    r2962 r2992  
    11// Box Backup Win32 native port by Nick Knight 
    2  
    3 // Need at least 0x0500 to use GetFileSizeEx on Cygwin/MinGW 
    4 #define WINVER 0x0500 
    52 
    63#include "emu.h" 
     
    10811078        } 
    10821079 
    1083         pDir->fd = _wfindfirst((const wchar_t*)pDir->name, &(pDir->info)); 
    1084  
    1085         if (pDir->fd == -1) 
     1080        pDir->fd = FindFirstFileW(pDir->name, &pDir->info); 
     1081        DWORD tmp = GetLastError(); 
     1082 
     1083        if (pDir->fd == INVALID_HANDLE_VALUE) 
    10861084        { 
    10871085                delete [] pDir->name; 
     
    11121110                struct dirent *den = NULL; 
    11131111 
    1114                 if (dp && dp->fd != -1) 
    1115                 { 
    1116                         if (!dp->result.d_name ||  
    1117                                 _wfindnext(dp->fd, &dp->info) != -1) 
     1112                if (dp && dp->fd != INVALID_HANDLE_VALUE) 
     1113                { 
     1114                        // first time around, when dp->result.d_name == NULL, use 
     1115                        // the values returned by FindFirstFile. After that, call 
     1116                        // FindNextFileW to return new ones. 
     1117                        if (!dp->result.d_name || 
     1118                                FindNextFileW(dp->fd, &dp->info) != 0) 
    11181119                        { 
    11191120                                den = &dp->result; 
    1120                                 std::wstring input(dp->info.name); 
     1121                                std::wstring input(dp->info.cFileName); 
    11211122                                memset(tempbuff, 0, sizeof(tempbuff)); 
    1122                                 WideCharToMultiByte(CP_UTF8, 0, dp->info.name,  
     1123                                WideCharToMultiByte(CP_UTF8, 0, dp->info.cFileName,  
    11231124                                        -1, &tempbuff[0], sizeof (tempbuff),  
    11241125                                        NULL, NULL); 
    11251126                                //den->d_name = (char *)dp->info.name; 
    11261127                                den->d_name = &tempbuff[0]; 
    1127                                 if (dp->info.attrib & FILE_ATTRIBUTE_DIRECTORY) 
     1128                                den->d_type = dp->info.dwFileAttributes; 
     1129                        } 
     1130                        else // FindNextFileW failed 
     1131                        { 
     1132                                // Why did it fail? No more files? 
     1133                                winerrno = GetLastError(); 
     1134                                den = NULL; 
     1135 
     1136                                if (winerrno == ERROR_NO_MORE_FILES) 
    11281137                                { 
    1129                                         den->d_type = S_IFDIR; 
     1138                                        errno = 0; // no more files 
    11301139                                } 
    11311140                                else 
    11321141                                { 
    1133                                         den->d_type = S_IFREG; 
     1142                                        errno = ENOSYS; 
    11341143                                } 
    11351144                        } 
     
    11391148                        errno = EBADF; 
    11401149                } 
     1150 
    11411151                return den; 
    11421152        } 
     
    11601170        try 
    11611171        { 
    1162                 int finres = -1; 
     1172                BOOL finres = false; 
     1173 
    11631174                if (dp) 
    11641175                { 
    1165                         if(dp->fd != -1) 
     1176                        if(dp->fd != INVALID_HANDLE_VALUE) 
    11661177                        { 
    1167                                 finres = _findclose(dp->fd); 
     1178                                finres = FindClose(dp->fd); 
    11681179                        } 
    11691180 
     
    11721183                } 
    11731184 
    1174                 if (finres == -1) // errors go to EBADF  
    1175                 { 
     1185                if (finres == FALSE) // errors go to EBADF  
     1186                { 
     1187                        winerrno = GetLastError(); 
    11761188                        errno = EBADF; 
    11771189                } 
    11781190 
    1179                 return finres; 
     1191                return (finres == TRUE) ? 0 : -1; 
    11801192        } 
    11811193        catch (...) 
  • box/trunk/lib/win32/emu.h

    r2929 r2992  
    5151#endif 
    5252 
     53// We need WINVER at least 0x0500 to use GetFileSizeEx on Cygwin/MinGW, 
     54// and 0x0501 for FindFirstFile(W) for opendir/readdir. 
     55// 
    5356// WIN32_WINNT versions 0x0600 (Vista) and higher enable WSAPoll() in 
    5457// winsock2.h, whose struct pollfd conflicts with ours below, so for 
    55 // now we just set it lower than that, to Windows 2000. 
     58// now we just set it lower than that, to Windows XP (0x0501). 
     59 
    5660#ifdef WINVER 
    57         #if WINVER != 0x0500 
    58                 #error Must include emu.h before setting WINVER 
    59         #endif 
    60 #endif 
    61 #define WINVER 0x0500 
     61#       if WINVER != 0x0501 
     62// provoke a redefinition warning to track down the offender 
     63#               define WINVER 0x0501 
     64#               error Must include emu.h before setting WINVER 
     65#       endif 
     66#endif 
     67#define WINVER 0x0501 
    6268 
    6369#ifdef _WIN32_WINNT 
    64         #if _WIN32_WINNT != 0x0500 
    65                 #error Must include emu.h before setting _WIN32_WINNT 
    66         #endif 
    67 #endif 
    68 #define _WIN32_WINNT 0x0500 
     70#       if _WIN32_WINNT != 0x0501 
     71// provoke a redefinition warning to track down the offender 
     72#               define _WIN32_WINNT 0x0501 
     73#               error Must include emu.h before setting _WIN32_WINNT 
     74#       endif 
     75#endif 
     76#define _WIN32_WINNT 0x0501 
    6977 
    7078// Windows headers 
     
    238246{ 
    239247        char *d_name; 
    240         unsigned long d_type; 
     248        DWORD d_type; // file attributes 
    241249}; 
    242250 
    243251struct DIR 
    244252{ 
    245         intptr_t                fd;     // filedescriptor 
    246         // struct _finddata_t   info; 
    247         struct _wfinddata_t     info; 
    248         // struct _finddata_t   info; 
    249         struct dirent           result; // d_name (first time null) 
    250         wchar_t                 *name;  // null-terminated byte string 
     253        HANDLE           fd;     // the HANDLE returned by FindFirstFile 
     254        WIN32_FIND_DATAW info; 
     255        struct dirent    result; // d_name (first time null) 
     256        wchar_t*         name;   // null-terminated byte string 
    251257}; 
    252258 
Note: See TracChangeset for help on using the changeset viewer.