Ignore:
Timestamp:
01/11/2011 23:38:59 (7 months ago)
Author:
chris
Message:

Test that invalid directory entries (pointers to nonexistent objects) are removed properly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/test/backupstorefix/testbackupstorefix.cpp

    r2269 r3040  
    1818 
    1919#include "Test.h" 
     20#include "BackupStoreCheck.h" 
    2021#include "BackupStoreConstants.h" 
    2122#include "BackupStoreDirectory.h" 
     
    216217                check_dir(dir, ck); 
    217218        } 
     219 
    218220        { 
    219221                BackupStoreDirectory dir; 
     
    298300 
    299301        // Start the bbstored server 
    300         int pid = LaunchServer(BBSTORED " testfiles/bbstored.conf",  
     302        int bbstored_pid = LaunchServer(BBSTORED " testfiles/bbstored.conf",  
    301303                "testfiles/bbstored.pid"); 
    302         TEST_THAT(pid != -1 && pid != 0); 
    303  
    304         if(pid > 0) 
    305         { 
    306                 ::sleep(1); 
    307                 TEST_THAT(ServerIsAlive(pid)); 
    308  
    309                 // Run the perl script to create the initial directories 
    310                 TEST_THAT_ABORTONFAIL(::system(PERL_EXECUTABLE  
    311                         " testfiles/testbackupstorefix.pl init") == 0); 
    312  
    313                 std::string cmd = BBACKUPD " " + bbackupd_args + 
    314                         " testfiles/bbackupd.conf"; 
    315                 int bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid"); 
    316                 TEST_THAT(bbackupd_pid != -1 && bbackupd_pid != 0); 
    317  
    318                 if(bbackupd_pid > 0) 
    319                 { 
    320                         ::safe_sleep(1); 
    321                         TEST_THAT(ServerIsAlive(bbackupd_pid)); 
    322  
    323                         // Wait 4 more seconds for the files to be old enough 
    324                         // to upload 
    325                         ::safe_sleep(4); 
    326          
    327                         // Upload files to create a nice store directory 
    328                         ::sync_and_wait(); 
    329  
    330                         // Stop bbackupd 
    331                         #ifdef WIN32 
    332                                 terminate_bbackupd(bbackupd_pid); 
    333                                 // implicit check for memory leaks 
    334                         #else 
    335                                 TEST_THAT(KillServer(bbackupd_pid)); 
    336                                 TestRemoteProcessMemLeaks("bbackupd.memleaks"); 
    337                         #endif 
    338                 } 
    339                  
    340                 // Generate a list of all the object IDs 
    341                 TEST_THAT_ABORTONFAIL(::system(BBACKUPQUERY " -Wwarning " 
    342                         "-c testfiles/bbackupd.conf \"list -r\" quit " 
    343                         "> testfiles/initial-listing.txt") == 0); 
    344  
    345                 // And load it in 
    346                 { 
    347                         FILE *f = ::fopen("testfiles/initial-listing.txt", "r"); 
    348                         TEST_THAT_ABORTONFAIL(f != 0); 
    349                         char line[512]; 
    350                         int32_t id; 
    351                         char flags[32]; 
    352                         char name[256]; 
    353                         while(::fgets(line, sizeof(line), f) != 0) 
     304        TEST_THAT(bbstored_pid > 0); 
     305        if (bbstored_pid <= 0) return 1; 
     306         
     307        ::sleep(1); 
     308        TEST_THAT(ServerIsAlive(bbstored_pid)); 
     309 
     310        // Run the perl script to create the initial directories 
     311        TEST_THAT_ABORTONFAIL(::system(PERL_EXECUTABLE  
     312                " testfiles/testbackupstorefix.pl init") == 0); 
     313 
     314        std::string cmd = BBACKUPD " " + bbackupd_args + 
     315                " testfiles/bbackupd.conf"; 
     316        int bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid"); 
     317        TEST_THAT(bbackupd_pid > 0); 
     318        if (bbackupd_pid <= 0) return 1; 
     319 
     320        ::safe_sleep(1); 
     321        TEST_THAT(ServerIsAlive(bbackupd_pid)); 
     322 
     323        // Wait 4 more seconds for the files to be old enough 
     324        // to upload 
     325        ::safe_sleep(4); 
     326 
     327        // Upload files to create a nice store directory 
     328        ::sync_and_wait(); 
     329 
     330        // Stop bbackupd 
     331        #ifdef WIN32 
     332                terminate_bbackupd(bbackupd_pid); 
     333                // implicit check for memory leaks 
     334        #else 
     335                TEST_THAT(KillServer(bbackupd_pid)); 
     336                TestRemoteProcessMemLeaks("bbackupd.memleaks"); 
     337        #endif 
     338 
     339        // Add a reference to a file that doesn't exist, check that it's removed 
     340        { 
     341                std::string fn; 
     342                StoreStructure::MakeObjectFilename(1 /* root */, storeRoot, 
     343                        discSetNum, fn, true /* EnsureDirectoryExists */); 
     344 
     345                std::auto_ptr<RaidFileRead> file(RaidFileRead::Open(discSetNum, 
     346                        fn)); 
     347                BackupStoreDirectory dir; 
     348                dir.ReadFromStream(*file, IOStream::TimeOutInfinite); 
     349                 
     350                dir.AddEntry(fnames[0], 12, 0x1234567890123456LL /* id */, 1, 
     351                        BackupStoreDirectory::Entry::Flags_File, 2); 
     352                 
     353                RaidFileWrite d(discSetNum, fn); 
     354                d.Open(true /* allow overwrite */); 
     355                dir.WriteToStream(d); 
     356                d.Commit(true /* write now! */); 
     357 
     358                file = RaidFileRead::Open(discSetNum, fn); 
     359                dir.ReadFromStream(*file, IOStream::TimeOutInfinite); 
     360                TEST_THAT(dir.FindEntryByID(0x1234567890123456LL) != 0); 
     361 
     362                // Check it 
     363                BackupStoreCheck checker(storeRoot, discSetNum, 
     364                        0x01234567, true /* FixErrors */, false /* Quiet */); 
     365                checker.Check(); 
     366                TEST_EQUAL(1, checker.GetNumErrorsFound()); 
     367 
     368                file = RaidFileRead::Open(discSetNum, fn); 
     369                dir.ReadFromStream(*file, IOStream::TimeOutInfinite); 
     370                TEST_THAT(dir.FindEntryByID(0x1234567890123456LL) == 0); 
     371        } 
     372 
     373        if (failures > 0) return 1; 
     374         
     375        // Generate a list of all the object IDs 
     376        TEST_THAT_ABORTONFAIL(::system(BBACKUPQUERY " -Wwarning " 
     377                "-c testfiles/bbackupd.conf \"list -r\" quit " 
     378                "> testfiles/initial-listing.txt") == 0); 
     379 
     380        // And load it in 
     381        { 
     382                FILE *f = ::fopen("testfiles/initial-listing.txt", "r"); 
     383                TEST_THAT_ABORTONFAIL(f != 0); 
     384                char line[512]; 
     385                int32_t id; 
     386                char flags[32]; 
     387                char name[256]; 
     388                while(::fgets(line, sizeof(line), f) != 0) 
     389                { 
     390                        TEST_THAT(::sscanf(line, "%x %s %s", &id,  
     391                                flags, name) == 3); 
     392                        bool isDir = (::strcmp(flags, "-d---") == 0); 
     393                        //TRACE3("%x,%d,%s\n", id, isDir, name); 
     394                        MEMLEAKFINDER_NO_LEAKS; 
     395                        nameToID[std::string(name)] = id; 
     396                        objectIsDir[id] = isDir; 
     397                } 
     398                ::fclose(f); 
     399        } 
     400 
     401        // ------------------------------------------------------------------------------------------------              
     402        ::printf("  === Delete store info, add random file\n"); 
     403        { 
     404                // Delete store info 
     405                RaidFileWrite del(discSetNum, storeRoot + "info"); 
     406                del.Delete(); 
     407        } 
     408        { 
     409                // Add a spurious file 
     410                RaidFileWrite random(discSetNum,  
     411                        storeRoot + "randomfile"); 
     412                random.Open(); 
     413                random.Write("test", 4); 
     414                random.Commit(true); 
     415        } 
     416 
     417        // Fix it 
     418        RUN_CHECK 
     419 
     420        // Check everything is as it was 
     421        TEST_THAT(::system(PERL_EXECUTABLE  
     422                " testfiles/testbackupstorefix.pl check 0") == 0); 
     423        // Check the random file doesn't exist 
     424        { 
     425                TEST_THAT(!RaidFileRead::FileExists(discSetNum,  
     426                        storeRoot + "01/randomfile")); 
     427        } 
     428 
     429        // ------------------------------------------------------------------------------------------------              
     430        ::printf("  === Delete an entry for an object from dir, change that object to be a patch, check it's deleted\n"); 
     431        { 
     432                // Open dir and find entry 
     433                int64_t delID = getID("Test1/cannes/ict/metegoguered/oats"); 
     434                { 
     435                        BackupStoreDirectory dir; 
     436                        LoadDirectory("Test1/cannes/ict/metegoguered", dir); 
     437                        TEST_THAT(dir.FindEntryByID(delID) != 0); 
     438                        dir.DeleteEntry(delID); 
     439                        SaveDirectory("Test1/cannes/ict/metegoguered", dir); 
     440                } 
     441                 
     442                // Adjust that entry 
     443                // 
     444                // IMPORTANT NOTE: There's a special hack in testbackupstorefix.pl to make sure that 
     445                // the file we're modifiying has at least two blocks so we can modify it and produce a valid file 
     446                // which will pass the verify checks. 
     447                // 
     448                std::string fn(getObjectName(delID)); 
     449                { 
     450                        std::auto_ptr<RaidFileRead> file(RaidFileRead::Open(discSetNum, fn)); 
     451                        RaidFileWrite f(discSetNum, fn); 
     452                        f.Open(true /* allow overwrite */); 
     453                        // Make a copy of the original 
     454                        file->CopyStreamTo(f); 
     455                        // Move to header in both 
     456                        file->Seek(0, IOStream::SeekType_Absolute); 
     457                        BackupStoreFile::MoveStreamPositionToBlockIndex(*file); 
     458                        f.Seek(file->GetPosition(), IOStream::SeekType_Absolute); 
     459                        // Read header 
     460                        struct 
    354461                        { 
    355                                 TEST_THAT(::sscanf(line, "%x %s %s", &id,  
    356                                         flags, name) == 3); 
    357                                 bool isDir = (::strcmp(flags, "-d---") == 0); 
    358                                 //TRACE3("%x,%d,%s\n", id, isDir, name); 
    359                                 MEMLEAKFINDER_NO_LEAKS; 
    360                                 nameToID[std::string(name)] = id; 
    361                                 objectIsDir[id] = isDir; 
    362                         } 
    363                         ::fclose(f); 
    364                 } 
    365  
    366                 // ------------------------------------------------------------------------------------------------              
    367                 ::printf("  === Delete store info, add random file\n"); 
    368                 { 
    369                         // Delete store info 
    370                         RaidFileWrite del(discSetNum, storeRoot + "info"); 
    371                         del.Delete(); 
    372                 } 
    373                 { 
    374                         // Add a spurious file 
    375                         RaidFileWrite random(discSetNum,  
    376                                 storeRoot + "randomfile"); 
    377                         random.Open(); 
    378                         random.Write("test", 4); 
    379                         random.Commit(true); 
     462                                file_BlockIndexHeader hdr; 
     463                                file_BlockIndexEntry e[2]; 
     464                        } h; 
     465                        TEST_THAT(file->Read(&h, sizeof(h)) == sizeof(h)); 
     466                        file->Close(); 
     467 
     468                        // Modify 
     469                        TEST_THAT(box_ntoh64(h.hdr.mOtherFileID) == 0); 
     470                        TEST_THAT(box_ntoh64(h.hdr.mNumBlocks) >= 2); 
     471                        h.hdr.mOtherFileID = box_hton64(2345); // don't worry about endianness 
     472                        h.e[0].mEncodedSize = box_hton64((box_ntoh64(h.e[0].mEncodedSize)) + (box_ntoh64(h.e[1].mEncodedSize))); 
     473                        h.e[1].mOtherBlockIndex = box_hton64(static_cast<uint64_t>(-2)); 
     474                        // Write to modified file 
     475                        f.Write(&h, sizeof(h)); 
     476                        // Commit new version 
     477                        f.Commit(true /* write now! */); 
    380478                } 
    381479 
    382480                // Fix it 
    383481                RUN_CHECK 
    384  
    385                 // Check everything is as it was 
     482                // Check 
    386483                TEST_THAT(::system(PERL_EXECUTABLE  
    387                         " testfiles/testbackupstorefix.pl check 0") == 0); 
    388                 // Check the random file doesn't exist 
    389                 { 
    390                         TEST_THAT(!RaidFileRead::FileExists(discSetNum,  
    391                                 storeRoot + "01/randomfile")); 
    392                 } 
    393  
    394                 // ------------------------------------------------------------------------------------------------              
    395                 ::printf("  === Delete an entry for an object from dir, change that object to be a patch, check it's deleted\n"); 
    396                 { 
    397                         // Open dir and find entry 
    398                         int64_t delID = getID("Test1/cannes/ict/metegoguered/oats"); 
    399                         { 
    400                                 BackupStoreDirectory dir; 
    401                                 LoadDirectory("Test1/cannes/ict/metegoguered", dir); 
    402                                 TEST_THAT(dir.FindEntryByID(delID) != 0); 
    403                                 dir.DeleteEntry(delID); 
    404                                 SaveDirectory("Test1/cannes/ict/metegoguered", dir); 
    405                         } 
    406                          
    407                         // Adjust that entry 
    408                         // 
    409                         // IMPORTANT NOTE: There's a special hack in testbackupstorefix.pl to make sure that 
    410                         // the file we're modifiying has at least two blocks so we can modify it and produce a valid file 
    411                         // which will pass the verify checks. 
    412                         // 
    413                         std::string fn(getObjectName(delID)); 
    414                         { 
    415                                 std::auto_ptr<RaidFileRead> file(RaidFileRead::Open(discSetNum, fn)); 
    416                                 RaidFileWrite f(discSetNum, fn); 
    417                                 f.Open(true /* allow overwrite */); 
    418                                 // Make a copy of the original 
    419                                 file->CopyStreamTo(f); 
    420                                 // Move to header in both 
    421                                 file->Seek(0, IOStream::SeekType_Absolute); 
    422                                 BackupStoreFile::MoveStreamPositionToBlockIndex(*file); 
    423                                 f.Seek(file->GetPosition(), IOStream::SeekType_Absolute); 
    424                                 // Read header 
    425                                 struct 
    426                                 { 
    427                                         file_BlockIndexHeader hdr; 
    428                                         file_BlockIndexEntry e[2]; 
    429                                 } h; 
    430                                 TEST_THAT(file->Read(&h, sizeof(h)) == sizeof(h)); 
    431                                 file->Close(); 
    432  
    433                                 // Modify 
    434                                 TEST_THAT(box_ntoh64(h.hdr.mOtherFileID) == 0); 
    435                                 TEST_THAT(box_ntoh64(h.hdr.mNumBlocks) >= 2); 
    436                                 h.hdr.mOtherFileID = box_hton64(2345); // don't worry about endianness 
    437                                 h.e[0].mEncodedSize = box_hton64((box_ntoh64(h.e[0].mEncodedSize)) + (box_ntoh64(h.e[1].mEncodedSize))); 
    438                                 h.e[1].mOtherBlockIndex = box_hton64(static_cast<uint64_t>(-2)); 
    439                                 // Write to modified file 
    440                                 f.Write(&h, sizeof(h)); 
    441                                 // Commit new version 
    442                                 f.Commit(true /* write now! */); 
    443                         } 
    444  
    445                         // Fix it 
    446                         RUN_CHECK 
    447                         // Check 
    448                         TEST_THAT(::system(PERL_EXECUTABLE  
    449                                 " testfiles/testbackupstorefix.pl check 1")  
    450                                 == 0); 
    451  
    452                         // Check the modified file doesn't exist 
    453                         TEST_THAT(!RaidFileRead::FileExists(discSetNum, fn)); 
    454                 } 
    455                  
    456                 // ------------------------------------------------------------------------------------------------              
    457                 ::printf("  === Delete directory, change container ID of another, duplicate entry in dir, spurious file size, delete file\n"); 
    458                 { 
    459                         BackupStoreDirectory dir; 
    460                         LoadDirectory("Test1/foreomizes/stemptinevidate/ict", dir); 
    461                         dir.SetContainerID(73773); 
    462                         SaveDirectory("Test1/foreomizes/stemptinevidate/ict", dir); 
    463                 } 
    464                 int64_t duplicatedID = 0; 
    465                 int64_t notSpuriousFileSize = 0; 
    466                 { 
    467                         BackupStoreDirectory dir; 
    468                         LoadDirectory("Test1/cannes/ict/peep", dir); 
    469                         // Duplicate the second entry 
    470                         { 
    471                                 BackupStoreDirectory::Iterator i(dir); 
    472                                 i.Next(); 
    473                                 BackupStoreDirectory::Entry *en = i.Next(); 
    474                                 TEST_THAT(en != 0); 
    475                                 duplicatedID = en->GetObjectID(); 
    476                                 dir.AddEntry(*en); 
    477                         } 
    478                         // Adjust file size of first file 
    479                         { 
    480                                 BackupStoreDirectory::Iterator i(dir); 
    481                                 BackupStoreDirectory::Entry *en = i.Next(BackupStoreDirectory::Entry::Flags_File); 
    482                                 TEST_THAT(en != 0); 
    483                                 notSpuriousFileSize = en->GetSizeInBlocks(); 
    484                                 en->SetSizeInBlocks(3473874); 
    485                                 TEST_THAT(en->GetSizeInBlocks() == 3473874); 
    486                         } 
    487                         SaveDirectory("Test1/cannes/ict/peep", dir); 
    488                 } 
    489                 // Delete a directory 
    490                 DeleteObject("Test1/pass/cacted/ming"); 
    491                 // Delete a file 
    492                 DeleteObject("Test1/cannes/ict/scely"); 
    493                 // Fix it 
    494                 RUN_CHECK 
    495                 // Check everything is as it should be 
    496                 TEST_THAT(::system(PERL_EXECUTABLE  
    497                         " testfiles/testbackupstorefix.pl check 2") == 0); 
    498                 { 
    499                         BackupStoreDirectory dir; 
    500                         LoadDirectory("Test1/foreomizes/stemptinevidate/ict", dir); 
    501                         TEST_THAT(dir.GetContainerID() == getID("Test1/foreomizes/stemptinevidate")); 
    502                 } 
    503                 { 
    504                         BackupStoreDirectory dir; 
    505                         LoadDirectory("Test1/cannes/ict/peep", dir); 
     484                        " testfiles/testbackupstorefix.pl check 1")  
     485                        == 0); 
     486 
     487                // Check the modified file doesn't exist 
     488                TEST_THAT(!RaidFileRead::FileExists(discSetNum, fn)); 
     489        } 
     490         
     491        // ------------------------------------------------------------------------------------------------              
     492        ::printf("  === Delete directory, change container ID of another, duplicate entry in dir, spurious file size, delete file\n"); 
     493        { 
     494                BackupStoreDirectory dir; 
     495                LoadDirectory("Test1/foreomizes/stemptinevidate/ict", dir); 
     496                dir.SetContainerID(73773); 
     497                SaveDirectory("Test1/foreomizes/stemptinevidate/ict", dir); 
     498        } 
     499        int64_t duplicatedID = 0; 
     500        int64_t notSpuriousFileSize = 0; 
     501        { 
     502                BackupStoreDirectory dir; 
     503                LoadDirectory("Test1/cannes/ict/peep", dir); 
     504                // Duplicate the second entry 
     505                { 
    506506                        BackupStoreDirectory::Iterator i(dir); 
    507                         // Count the number of entries with the ID which was duplicated 
    508                         int count = 0; 
    509                         BackupStoreDirectory::Entry *en = 0; 
    510                         while((en = i.Next()) != 0) 
    511                         { 
    512                                 if(en->GetObjectID() == duplicatedID) 
    513                                 { 
    514                                         ++count; 
    515                                 } 
    516                         } 
    517                         TEST_THAT(count == 1); 
    518                         // Check file size has changed 
    519                         { 
    520                                 BackupStoreDirectory::Iterator i(dir); 
    521                                 BackupStoreDirectory::Entry *en = i.Next(BackupStoreDirectory::Entry::Flags_File); 
    522                                 TEST_THAT(en != 0); 
    523                                 TEST_THAT(en->GetSizeInBlocks() == notSpuriousFileSize); 
    524                         } 
    525                 } 
    526  
    527                 // ------------------------------------------------------------------------------------------------              
    528                 ::printf("  === Modify the obj ID of dir, delete dir with no members, add extra reference to a file\n"); 
    529                 // Set bad object ID 
    530                 { 
    531                         BackupStoreDirectory dir; 
    532                         LoadDirectory("Test1/foreomizes/stemptinevidate/ict", dir); 
    533                         dir.TESTONLY_SetObjectID(73773); 
    534                         SaveDirectory("Test1/foreomizes/stemptinevidate/ict", dir); 
    535                 } 
    536                 // Delete dir with no members 
    537                 DeleteObject("Test1/dir-no-members"); 
    538                 // Add extra reference 
    539                 { 
    540                         BackupStoreDirectory dir; 
    541                         LoadDirectory("Test1/divel", dir); 
     507                        i.Next(); 
     508                        BackupStoreDirectory::Entry *en = i.Next(); 
     509                        TEST_THAT(en != 0); 
     510                        duplicatedID = en->GetObjectID(); 
     511                        dir.AddEntry(*en); 
     512                } 
     513                // Adjust file size of first file 
     514                { 
    542515                        BackupStoreDirectory::Iterator i(dir); 
    543516                        BackupStoreDirectory::Entry *en = i.Next(BackupStoreDirectory::Entry::Flags_File); 
    544517                        TEST_THAT(en != 0); 
    545                         BackupStoreDirectory dir2; 
    546                         LoadDirectory("Test1/divel/torsines/cruishery", dir2); 
    547                         dir2.AddEntry(*en); 
    548                         SaveDirectory("Test1/divel/torsines/cruishery", dir2); 
    549                 } 
    550                 // Fix it 
    551                 RUN_CHECK 
    552                 // Check everything is as it should be 
    553                 TEST_THAT(::system(PERL_EXECUTABLE  
    554                         " testfiles/testbackupstorefix.pl check 3") == 0); 
    555                 { 
    556                         BackupStoreDirectory dir; 
    557                         LoadDirectory("Test1/foreomizes/stemptinevidate/ict", dir); 
    558                         TEST_THAT(dir.GetObjectID() == getID("Test1/foreomizes/stemptinevidate/ict")); 
    559                 } 
    560                  
    561                 // ------------------------------------------------------------------------------------------------              
    562                 ::printf("  === Orphan files and dirs without being recoverable\n"); 
    563                 DeleteObject("Test1/dir1");              
    564                 DeleteObject("Test1/dir1/dir2");                 
    565                 // Fix it 
    566                 RUN_CHECK 
    567                 // Check everything is where it is predicted to be 
    568                 TEST_THAT(::system(PERL_EXECUTABLE  
    569                         " testfiles/testbackupstorefix.pl check 4") == 0); 
    570  
    571                 // ------------------------------------------------------------------------------------------------              
    572                 ::printf("  === Corrupt file and dir\n"); 
    573                 // File 
    574                 CorruptObject("Test1/foreomizes/stemptinevidate/algoughtnerge", 
    575                         33, "34i729834298349283479233472983sdfhasgs"); 
    576                 // Dir 
    577                 CorruptObject("Test1/cannes/imulatrougge/foreomizes",23,  
    578                         "dsf32489sdnadf897fd2hjkesdfmnbsdfcsfoisufio2iofe2hdfkjhsf"); 
    579                 // Fix it 
    580                 RUN_CHECK 
    581                 // Check everything is where it should be 
    582                 TEST_THAT(::system(PERL_EXECUTABLE  
    583                         " testfiles/testbackupstorefix.pl check 5") == 0); 
    584  
    585                 // ------------------------------------------------------------------------------------------------              
    586                 ::printf("  === Overwrite root with a file\n"); 
    587                 { 
    588                         std::auto_ptr<RaidFileRead> r(RaidFileRead::Open(discSetNum, getObjectName(getID("Test1/pass/shuted/brightinats/milamptimaskates")))); 
    589                         RaidFileWrite w(discSetNum, getObjectName(1 /* root */)); 
    590                         w.Open(true /* allow overwrite */); 
    591                         r->CopyStreamTo(w); 
    592                         w.Commit(true /* convert now */); 
    593                 } 
    594                 // Fix it 
    595                 RUN_CHECK 
    596                 // Check everything is where it should be 
    597                 TEST_THAT(::system(PERL_EXECUTABLE  
    598                         " testfiles/testbackupstorefix.pl reroot 6") == 0); 
    599  
    600  
    601                 // --------------------------------------------------------- 
    602                 // Stop server 
    603                 TEST_THAT(KillServer(pid)); 
    604  
    605                 #ifdef WIN32 
    606                         TEST_THAT(unlink("testfiles/bbstored.pid") == 0); 
    607                 #else 
    608                         TestRemoteProcessMemLeaks("bbstored.memleaks"); 
    609                 #endif 
    610         } 
     518                        notSpuriousFileSize = en->GetSizeInBlocks(); 
     519                        en->SetSizeInBlocks(3473874); 
     520                        TEST_THAT(en->GetSizeInBlocks() == 3473874); 
     521                } 
     522                SaveDirectory("Test1/cannes/ict/peep", dir); 
     523        } 
     524        // Delete a directory 
     525        DeleteObject("Test1/pass/cacted/ming"); 
     526        // Delete a file 
     527        DeleteObject("Test1/cannes/ict/scely"); 
     528        // Fix it 
     529        RUN_CHECK 
     530        // Check everything is as it should be 
     531        TEST_THAT(::system(PERL_EXECUTABLE  
     532                " testfiles/testbackupstorefix.pl check 2") == 0); 
     533        { 
     534                BackupStoreDirectory dir; 
     535                LoadDirectory("Test1/foreomizes/stemptinevidate/ict", dir); 
     536                TEST_THAT(dir.GetContainerID() == getID("Test1/foreomizes/stemptinevidate")); 
     537        } 
     538        { 
     539                BackupStoreDirectory dir; 
     540                LoadDirectory("Test1/cannes/ict/peep", dir); 
     541                BackupStoreDirectory::Iterator i(dir); 
     542                // Count the number of entries with the ID which was duplicated 
     543                int count = 0; 
     544                BackupStoreDirectory::Entry *en = 0; 
     545                while((en = i.Next()) != 0) 
     546                { 
     547                        if(en->GetObjectID() == duplicatedID) 
     548                        { 
     549                                ++count; 
     550                        } 
     551                } 
     552                TEST_THAT(count == 1); 
     553                // Check file size has changed 
     554                { 
     555                        BackupStoreDirectory::Iterator i(dir); 
     556                        BackupStoreDirectory::Entry *en = i.Next(BackupStoreDirectory::Entry::Flags_File); 
     557                        TEST_THAT(en != 0); 
     558                        TEST_THAT(en->GetSizeInBlocks() == notSpuriousFileSize); 
     559                } 
     560        } 
     561 
     562        // ------------------------------------------------------------------------------------------------              
     563        ::printf("  === Modify the obj ID of dir, delete dir with no members, add extra reference to a file\n"); 
     564        // Set bad object ID 
     565        { 
     566                BackupStoreDirectory dir; 
     567                LoadDirectory("Test1/foreomizes/stemptinevidate/ict", dir); 
     568                dir.TESTONLY_SetObjectID(73773); 
     569                SaveDirectory("Test1/foreomizes/stemptinevidate/ict", dir); 
     570        } 
     571        // Delete dir with no members 
     572        DeleteObject("Test1/dir-no-members"); 
     573        // Add extra reference 
     574        { 
     575                BackupStoreDirectory dir; 
     576                LoadDirectory("Test1/divel", dir); 
     577                BackupStoreDirectory::Iterator i(dir); 
     578                BackupStoreDirectory::Entry *en = i.Next(BackupStoreDirectory::Entry::Flags_File); 
     579                TEST_THAT(en != 0); 
     580                BackupStoreDirectory dir2; 
     581                LoadDirectory("Test1/divel/torsines/cruishery", dir2); 
     582                dir2.AddEntry(*en); 
     583                SaveDirectory("Test1/divel/torsines/cruishery", dir2); 
     584        } 
     585        // Fix it 
     586        RUN_CHECK 
     587        // Check everything is as it should be 
     588        TEST_THAT(::system(PERL_EXECUTABLE  
     589                " testfiles/testbackupstorefix.pl check 3") == 0); 
     590        { 
     591                BackupStoreDirectory dir; 
     592                LoadDirectory("Test1/foreomizes/stemptinevidate/ict", dir); 
     593                TEST_THAT(dir.GetObjectID() == getID("Test1/foreomizes/stemptinevidate/ict")); 
     594        } 
     595         
     596        // ------------------------------------------------------------------------------------------------              
     597        ::printf("  === Orphan files and dirs without being recoverable\n"); 
     598        DeleteObject("Test1/dir1");              
     599        DeleteObject("Test1/dir1/dir2");                 
     600        // Fix it 
     601        RUN_CHECK 
     602        // Check everything is where it is predicted to be 
     603        TEST_THAT(::system(PERL_EXECUTABLE  
     604                " testfiles/testbackupstorefix.pl check 4") == 0); 
     605 
     606        // ------------------------------------------------------------------------------------------------              
     607        ::printf("  === Corrupt file and dir\n"); 
     608        // File 
     609        CorruptObject("Test1/foreomizes/stemptinevidate/algoughtnerge", 
     610                33, "34i729834298349283479233472983sdfhasgs"); 
     611        // Dir 
     612        CorruptObject("Test1/cannes/imulatrougge/foreomizes",23,  
     613                "dsf32489sdnadf897fd2hjkesdfmnbsdfcsfoisufio2iofe2hdfkjhsf"); 
     614        // Fix it 
     615        RUN_CHECK 
     616        // Check everything is where it should be 
     617        TEST_THAT(::system(PERL_EXECUTABLE  
     618                " testfiles/testbackupstorefix.pl check 5") == 0); 
     619 
     620        // ------------------------------------------------------------------------------------------------              
     621        ::printf("  === Overwrite root with a file\n"); 
     622        { 
     623                std::auto_ptr<RaidFileRead> r(RaidFileRead::Open(discSetNum, getObjectName(getID("Test1/pass/shuted/brightinats/milamptimaskates")))); 
     624                RaidFileWrite w(discSetNum, getObjectName(1 /* root */)); 
     625                w.Open(true /* allow overwrite */); 
     626                r->CopyStreamTo(w); 
     627                w.Commit(true /* convert now */); 
     628        } 
     629        // Fix it 
     630        RUN_CHECK 
     631        // Check everything is where it should be 
     632        TEST_THAT(::system(PERL_EXECUTABLE  
     633                " testfiles/testbackupstorefix.pl reroot 6") == 0); 
     634 
     635 
     636        // --------------------------------------------------------- 
     637        // Stop server 
     638        TEST_THAT(KillServer(bbstored_pid)); 
     639 
     640        #ifdef WIN32 
     641                TEST_THAT(unlink("testfiles/bbstored.pid") == 0); 
     642        #else 
     643                TestRemoteProcessMemLeaks("bbstored.memleaks"); 
     644        #endif 
    611645 
    612646        return 0; 
Note: See TracChangeset for help on using the changeset viewer.