Ignore:
Timestamp:
08/03/2010 22:00:55 (2 years ago)
Author:
chris
Message:

Merge [2604] [2612] [2613] [2614] [2618] [2633] [2634] [2635] [2636]
from trunk into 0.11rc7. Fix updating of changed file attributes
(creation time) on Windows, fixes #64 in 0.11rc7.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/RELEASE/0.11rc7/lib/backupclient/BackupClientFileAttributes.cpp

    r2493 r2663  
    7979{ 
    8080        int32_t uid, gid, mode; 
     81        #ifdef WIN32 
     82        int64_t fileCreationTime; 
     83        #endif 
    8184} attributeHashData; 
    8285 
     
    222225// Function 
    223226//              Name:    BackupClientFileAttributes::Compare(const BackupClientFileAttributes &, bool) 
    224 //              Purpose: Compare, optionally ignoring the attribute modification time and/or modification time, and some data which is 
    225 //                               irrelevant in practise (eg file generation number) 
     227//              Purpose: Compare, optionally ignoring the attribute 
     228//                       modification time and/or modification time, and some 
     229//                       data which is irrelevant in practise (eg file 
     230//                       generation number) 
    226231//              Created: 10/12/03 
    227232// 
    228233// -------------------------------------------------------------------------- 
    229 bool BackupClientFileAttributes::Compare(const BackupClientFileAttributes &rAttr, bool IgnoreAttrModTime, bool IgnoreModTime) const 
     234bool BackupClientFileAttributes::Compare(const BackupClientFileAttributes &rAttr, 
     235        bool IgnoreAttrModTime, bool IgnoreModTime) const 
    230236{ 
    231237        EnsureClearAvailable(); 
     
    235241        if(mpClearAttributes->GetSize() != rAttr.mpClearAttributes->GetSize()) 
    236242        { 
     243                BOX_TRACE("Attribute Compare: Attributes objects are " 
     244                        "different sizes, cannot compare them: local " << 
     245                        mpClearAttributes->GetSize() << " bytes, remote " << 
     246                        rAttr.mpClearAttributes->GetSize() << " bytes"); 
    237247                return false; 
    238248        } 
     
    242252        attr_StreamFormat *a1 = (attr_StreamFormat*)mpClearAttributes->GetBuffer(); 
    243253        attr_StreamFormat *a2 = (attr_StreamFormat*)rAttr.mpClearAttributes->GetBuffer(); 
    244          
    245         if(a1->AttributeType != a2->AttributeType 
    246                 || a1->UID != a2->UID 
    247                 || a1->GID != a2->GID 
    248                 || a1->UserDefinedFlags != a2->UserDefinedFlags 
    249                 || a1->Mode != a2->Mode) 
    250         { 
    251                 return false; 
    252         } 
    253          
     254 
     255        #define COMPARE(attribute, message) \ 
     256        if (a1->attribute != a2->attribute) \ 
     257        { \ 
     258                BOX_TRACE("Attribute Compare: " << message << " differ: " \ 
     259                        "local "  << ntoh(a1->attribute) << ", " \ 
     260                        "remote " << ntoh(a2->attribute)); \ 
     261                return false; \ 
     262        } 
     263        COMPARE(AttributeType, "Attribute types"); 
     264        COMPARE(UID, "UIDs"); 
     265        COMPARE(GID, "GIDs"); 
     266        COMPARE(UserDefinedFlags, "User-defined flags"); 
     267        COMPARE(Mode, "Modes"); 
     268 
    254269        if(!IgnoreModTime) 
    255270        { 
    256                 int t1 = a1->ModificationTime / 1000000; 
    257                 int t2 = a2->ModificationTime / 1000000; 
    258                 if(t1 != t2) 
    259                 { 
     271                uint64_t t1 = box_ntoh64(a1->ModificationTime); 
     272                uint64_t t2 = box_ntoh64(a2->ModificationTime); 
     273                time_t s1 = BoxTimeToSeconds(t1); 
     274                time_t s2 = BoxTimeToSeconds(t2); 
     275                if(s1 != s2) 
     276                { 
     277                        BOX_TRACE("Attribute Compare: File modification " 
     278                                "times differ: local " << 
     279                                FormatTime(t1, true) << " (" << s1 << "), " 
     280                                "remote " << 
     281                                FormatTime(t2, true) << " (" << s2 << ")"); 
    260282                        return false; 
    261283                } 
    262284        } 
    263  
     285         
    264286        if(!IgnoreAttrModTime) 
    265287        { 
    266                 int t1 = a1->AttrModificationTime / 1000000; 
    267                 int t2 = a2->AttrModificationTime / 1000000; 
    268                 if(t1 != t2) 
    269                 { 
     288                uint64_t t1 = box_ntoh64(a1->AttrModificationTime); 
     289                uint64_t t2 = box_ntoh64(a2->AttrModificationTime); 
     290                time_t s1 = BoxTimeToSeconds(t1); 
     291                time_t s2 = BoxTimeToSeconds(t2); 
     292                if(s1 != s2) 
     293                { 
     294                        BOX_TRACE("Attribute Compare: Attribute modification " 
     295                                "times differ: local " << 
     296                                FormatTime(t1, true) << " (" << s1 << "), " 
     297                                "remote " << 
     298                                FormatTime(t2, true) << " (" << s2 << ")"); 
    270299                        return false; 
    271300                } 
     
    277306        { 
    278307                // Symlink strings don't match. This also compares xattrs 
    279                 if(::memcmp(a1 + 1, a2 + 1, size - sizeof(attr_StreamFormat)) != 0) 
    280                 { 
     308                int datalen = size - sizeof(attr_StreamFormat); 
     309 
     310                if(::memcmp(a1 + 1, a2 + 1, datalen) != 0) 
     311                { 
     312                        std::string s1((char *)(a1 + 1), datalen); 
     313                        std::string s2((char *)(a2 + 1), datalen); 
     314                        BOX_TRACE("Attribute Compare: Symbolic link target " 
     315                                "or extended attributes differ: " 
     316                                "local "  << PrintEscapedBinaryData(s1) << ", " 
     317                                "remote " << PrintEscapedBinaryData(s2)); 
    281318                        return false; 
    282319                } 
     
    604641} 
    605642 
     643// -------------------------------------------------------------------------- 
     644// 
     645// Function 
     646//              Name:    BackupClientFileAttributes::GetModificationTimes() 
     647//              Purpose: Returns the modification time embedded in the 
     648//                       attributes. 
     649//              Created: 2010/02/24 
     650// 
     651// -------------------------------------------------------------------------- 
     652void BackupClientFileAttributes::GetModificationTimes( 
     653        box_time_t *pModificationTime, 
     654        box_time_t *pAttrModificationTime) const 
     655{ 
     656        // Got something loaded 
     657        if(GetSize() <= 0) 
     658        { 
     659                THROW_EXCEPTION(BackupStoreException, AttributesNotLoaded); 
     660        } 
     661         
     662        // Make sure there are clear attributes to use 
     663        EnsureClearAvailable(); 
     664        ASSERT(mpClearAttributes != 0); 
     665 
     666        // Check if the decrypted attributes are small enough, and the type of attributes stored 
     667        if(mpClearAttributes->GetSize() < (int)sizeof(int32_t)) 
     668        { 
     669                THROW_EXCEPTION(BackupStoreException, AttributesNotUnderstood); 
     670        } 
     671        int32_t *type = (int32_t*)mpClearAttributes->GetBuffer(); 
     672        ASSERT(type != 0); 
     673        if(ntohl(*type) != ATTRIBUTETYPE_GENERIC_UNIX) 
     674        { 
     675                // Don't know what to do with these 
     676                THROW_EXCEPTION(BackupStoreException, AttributesNotUnderstood); 
     677        } 
     678         
     679        // Check there is enough space for an attributes block 
     680        if(mpClearAttributes->GetSize() < (int)sizeof(attr_StreamFormat)) 
     681        { 
     682                // Too small 
     683                THROW_EXCEPTION(BackupStoreException, AttributesNotLoaded); 
     684        } 
     685 
     686        // Get pointer to structure 
     687        attr_StreamFormat *pattr = (attr_StreamFormat*)mpClearAttributes->GetBuffer(); 
     688 
     689        if(pModificationTime) 
     690        { 
     691                *pModificationTime = box_ntoh64(pattr->ModificationTime); 
     692        } 
     693         
     694        if(pAttrModificationTime) 
     695        { 
     696                *pAttrModificationTime = box_ntoh64(pattr->AttrModificationTime); 
     697        } 
     698} 
    606699 
    607700// -------------------------------------------------------------------------- 
     
    10331126// 
    10341127// Function 
    1035 //              Name:    BackupClientFileAttributes::GenerateAttributeHash(struct stat &, const std::string &, const std::string &) 
    1036 //              Purpose: Generate a 64 bit hash from the attributes, used to detect changes. 
    1037 //                               Include filename in the hash, so that it changes from one file to another, 
    1038 //                               so don't reveal identical attributes. 
     1128//              Name:    BackupClientFileAttributes::GenerateAttributeHash( 
     1129//                       struct stat &, const std::string &, 
     1130//                       const std::string &) 
     1131//              Purpose: Generate a 64 bit hash from the attributes, used to 
     1132//                       detect changes. Include filename in the hash, so 
     1133//                       that it changes from one file to another, so don't 
     1134//                       reveal identical attributes. 
    10391135//              Created: 25/4/04 
    10401136// 
    10411137// -------------------------------------------------------------------------- 
    1042 uint64_t BackupClientFileAttributes::GenerateAttributeHash(EMU_STRUCT_STAT &st, const std::string &filename, const std::string &leafname) 
     1138uint64_t BackupClientFileAttributes::GenerateAttributeHash(EMU_STRUCT_STAT &st, 
     1139        const std::string &filename, const std::string &leafname) 
    10431140{ 
    10441141        if(sAttributeHashSecretLength == 0) 
     
    10551152        hashData.mode = htonl(st.st_mode); 
    10561153 
     1154        #ifdef WIN32 
     1155        // On Windows, the "file attribute modification time" is the 
     1156        // file creation time, and we want to back this up, restore 
     1157        // it and compare it. 
     1158        // 
     1159        // On other platforms, it's not very important and can't 
     1160        // reliably be set to anything other than the current time. 
     1161        hashData.fileCreationTime = box_hton64(st.st_ctime); 
     1162        #endif 
     1163 
    10571164        StreamableMemBlock xattr; 
    10581165        FillExtendedAttr(xattr, filename.c_str()); 
     
    10631170        digest.Add(xattr.GetBuffer(), xattr.GetSize()); 
    10641171        digest.Add(leafname.c_str(), leafname.size()); 
    1065         digest.Add(sAttributeHashSecret, sAttributeHashSecretLength); 
     1172        digest.Add(sAttributeHashSecret, sAttributeHashSecretLength);    
    10661173        digest.Finish(); 
    10671174         
Note: See TracChangeset for help on using the changeset viewer.