From 98940c6172c6cd9f4a75e2d0693bcdc0f09719ad Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Tue, 6 Apr 1999 18:22:41 +0000 Subject: [PATCH] Made ScheduledTasks to more work to reduce code bloat. git-svn-id: svn://10.0.0.236/branches/XPINSTALL_DEV_BRANCH@26483 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpinstall/src/ScheduledTasks.cpp | 99 ++++++++++++++-------- mozilla/xpinstall/src/ScheduledTasks.h | 2 +- mozilla/xpinstall/src/nsInstallDelete.cpp | 9 +- mozilla/xpinstall/src/nsInstallExecute.cpp | 7 +- mozilla/xpinstall/src/nsInstallFile.cpp | 36 +------- mozilla/xpinstall/src/nsInstallPatch.cpp | 58 +------------ mozilla/xpinstall/src/nsInstallPatch.h | 2 - mozilla/xpinstall/src/nsSoftwareUpdate.cpp | 5 +- 8 files changed, 75 insertions(+), 143 deletions(-) diff --git a/mozilla/xpinstall/src/ScheduledTasks.cpp b/mozilla/xpinstall/src/ScheduledTasks.cpp index 9183fd27b28..8b83a0dd73d 100644 --- a/mozilla/xpinstall/src/ScheduledTasks.cpp +++ b/mozilla/xpinstall/src/ScheduledTasks.cpp @@ -27,25 +27,35 @@ #include "NSReg.h" #include "nsFileSpec.h" #include "nsFileStream.h" +#include "nsInstall.h" // for error codes REGERR DeleteFileLater(nsFileSpec& filename) { - RKEY newkey; - REGERR result = -1; - HREG reg; - if ( REGERR_OK == NR_RegOpen("", ®) ) + + REGERR result = 0; + + filename.Delete(false); + + if (filename.Exists()) { - if (REGERR_OK == NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY, &newkey) ) + RKEY newkey; + HREG reg; + if ( REGERR_OK == NR_RegOpen("", ®) ) { - nsPersistentFileDescriptor savethis(filename); - char* buffer; - nsOutputStringStream s(buffer); - s << savethis; + if (REGERR_OK == NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY, &newkey) ) + { + nsPersistentFileDescriptor savethis(filename); + char* buffer; + nsOutputStringStream s(buffer); + s << savethis; - result = NR_RegSetEntry( reg, newkey, "", REGTYPE_ENTRY_BYTES, buffer, strlen(buffer)); + result = NR_RegSetEntry( reg, newkey, "", REGTYPE_ENTRY_BYTES, buffer, strlen(buffer)); + if (result == REGERR_OK) + result = nsInstall::REBOOT_NEEDED; + } + + NR_RegClose(reg); } - - NR_RegClose(reg); } return result; @@ -53,31 +63,52 @@ REGERR DeleteFileLater(nsFileSpec& filename) REGERR ReplaceFileLater(nsFileSpec& tmpfile, nsFileSpec& target ) { - RKEY newkey; - REGERR result; - HREG reg; - - if ( REGERR_OK == NR_RegOpen("", ®) ) + REGERR result = 0; + + if (! target.Exists() ) { - result = NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &newkey); - if ( result == REGERR_OK ) - { - nsPersistentFileDescriptor tempDesc(tmpfile); - nsPersistentFileDescriptor targDesc(target); - - char* tempBuffer; - char* targBuffer; + // Now that we have move the existing file, we can move the mExtracedFile into place. + nsFileSpec parentofFinalFile; - nsOutputStringStream tempStream(tempBuffer); - nsOutputStringStream targStream(targBuffer); - - tempStream << tempDesc; - targStream << targDesc; - - result = NR_RegSetEntry( reg, newkey, tempBuffer, REGTYPE_ENTRY_BYTES, targBuffer, strlen(targBuffer)); - } - NR_RegClose(reg); + target.GetParent(parentofFinalFile); + result = tmpfile.Move(parentofFinalFile); + + char* leafName = target.GetLeafName(); + tmpfile.Rename(leafName); + delete [] leafName; } + else + { + RKEY newkey; + HREG reg; + + if ( REGERR_OK == NR_RegOpen("", ®) ) + { + result = NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &newkey); + if ( result == REGERR_OK ) + { + nsPersistentFileDescriptor tempDesc(tmpfile); + nsPersistentFileDescriptor targDesc(target); + + char* tempBuffer; + char* targBuffer; + + nsOutputStringStream tempStream(tempBuffer); + nsOutputStringStream targStream(targBuffer); + + tempStream << tempDesc; + targStream << targDesc; + + result = NR_RegSetEntry( reg, newkey, tempBuffer, REGTYPE_ENTRY_BYTES, targBuffer, strlen(targBuffer)); + if (result == REGERR_OK) + result = nsInstall::REBOOT_NEEDED; + + } + + NR_RegClose(reg); + } + } + return result; } diff --git a/mozilla/xpinstall/src/ScheduledTasks.h b/mozilla/xpinstall/src/ScheduledTasks.h index 3dd4154f4ec..860d84c4f0c 100644 --- a/mozilla/xpinstall/src/ScheduledTasks.h +++ b/mozilla/xpinstall/src/ScheduledTasks.h @@ -36,7 +36,7 @@ REGERR DeleteFileLater(nsFileSpec& filename); REGERR ReplaceFileLater(nsFileSpec& tmpfile, nsFileSpec& target ); -extern "C" void PerformScheduledTasks(void *data) +extern "C" void PerformScheduledTasks(void *data); #endif \ No newline at end of file diff --git a/mozilla/xpinstall/src/nsInstallDelete.cpp b/mozilla/xpinstall/src/nsInstallDelete.cpp index b00071884c9..0d4afa87d24 100644 --- a/mozilla/xpinstall/src/nsInstallDelete.cpp +++ b/mozilla/xpinstall/src/nsInstallDelete.cpp @@ -222,14 +222,7 @@ PRInt32 nsInstallDelete::NativeComplete() { if (mFinalFile->IsFile()) { - mFinalFile->Delete(false); - - if (mFinalFile->Exists()) - { - // If file still exists, we need to delete it later! - DeleteFileLater(*mFinalFile); - return nsInstall::REBOOT_NEEDED; - } + return DeleteFileLater(*mFinalFile); } else { diff --git a/mozilla/xpinstall/src/nsInstallExecute.cpp b/mozilla/xpinstall/src/nsInstallExecute.cpp index 09b6b7a4648..946838b82ef 100644 --- a/mozilla/xpinstall/src/nsInstallExecute.cpp +++ b/mozilla/xpinstall/src/nsInstallExecute.cpp @@ -98,12 +98,7 @@ void nsInstallExecute::Abort() if (mExecutableFile == nsnull) return; - mExecutableFile->Delete(PR_FALSE); - - if ( mExecutableFile->Exists() ) - { - DeleteFileLater(*mExecutableFile); - } + DeleteFileLater(*mExecutableFile); } char* nsInstallExecute::toString() diff --git a/mozilla/xpinstall/src/nsInstallFile.cpp b/mozilla/xpinstall/src/nsInstallFile.cpp index 8927dde949a..f89d7e98470 100644 --- a/mozilla/xpinstall/src/nsInstallFile.cpp +++ b/mozilla/xpinstall/src/nsInstallFile.cpp @@ -200,41 +200,7 @@ PRInt32 nsInstallFile::CompleteFileMove() } else { - if (mFinalFile->Exists() == PR_FALSE) - { - // We can simple move the extracted file to the mFinalFile's parent - nsFileSpec parentofFinalFile; - - mFinalFile->GetParent(parentofFinalFile); - result = mExtracedFile->Move(parentofFinalFile); - - char* leafName = mFinalFile->GetLeafName(); - mExtracedFile->Rename(leafName); - delete [] leafName; - - } - else - { - mFinalFile->Delete(PR_FALSE); - - if (! mFinalFile->Exists()) - { - // Now that we have move the existing file, we can move the mExtracedFile into place. - nsFileSpec parentofFinalFile; - - mFinalFile->GetParent(parentofFinalFile); - result = mExtracedFile->Move(parentofFinalFile); - - char* leafName = mFinalFile->GetLeafName(); - mExtracedFile->Rename(leafName); - delete [] leafName; - } - else - { - ReplaceFileLater(*mExtracedFile, *mFinalFile ); - result = nsInstall::REBOOT_NEEDED; - } - } + result = ReplaceFileLater(*mExtracedFile, *mFinalFile ); } return result; diff --git a/mozilla/xpinstall/src/nsInstallPatch.cpp b/mozilla/xpinstall/src/nsInstallPatch.cpp index 1955731f511..e3a85edc73c 100644 --- a/mozilla/xpinstall/src/nsInstallPatch.cpp +++ b/mozilla/xpinstall/src/nsInstallPatch.cpp @@ -183,7 +183,7 @@ PRInt32 nsInstallPatch::Prepare() if ( deleteOldSrc ) { - NativeDeleteFile( fileName ); + DeleteFileLater(*fileName ); } return err; @@ -206,7 +206,7 @@ PRInt32 nsInstallPatch::Complete() if (fileName != nsnull && (*fileName == *mPatchedFile) ) { // the patch has not been superceded--do final replacement - err = NativeReplace( *mTargetFile, *mPatchedFile ); + err = ReplaceFileLater( *mTargetFile, *mPatchedFile ); if ( 0 == err || nsInstall::REBOOT_NEEDED == err ) { nsString tempVersionString; @@ -247,7 +247,7 @@ void nsInstallPatch::Abort() if (fileName != nsnull && (*fileName == *mPatchedFile) ) { - NativeDeleteFile( mPatchedFile ); + DeleteFileLater( *mPatchedFile ); } } @@ -279,58 +279,6 @@ nsInstallPatch::NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patc return -1; } -PRInt32 -nsInstallPatch::NativeDeleteFile(nsFileSpec* doomedFile) -{ - if (doomedFile->Exists()) - { - if (doomedFile->IsFile()) - { - doomedFile->Delete(false); - - if (doomedFile->Exists()) - { - // If file still exists, we need to delete it later! - DeleteFileLater(*doomedFile); - return nsInstall::REBOOT_NEEDED; - } - } - else - { - return nsInstall::FILE_IS_DIRECTORY; - } - } - - return nsInstall::FILE_DOES_NOT_EXIST; -} - -PRInt32 -nsInstallPatch::NativeReplace(nsFileSpec& oldfile, nsFileSpec& newFile) -{ - - oldfile.Delete(PR_FALSE); - if (oldfile.Exists()) - { - ReplaceFileLater(newFile, oldfile); - return nsInstall::REBOOT_NEEDED; - } - else - { - // We can simple move the extracted file to the mFinalFile's parent - nsFileSpec parentofFinalFile; - - oldfile.GetParent(parentofFinalFile); - newFile.Move(parentofFinalFile); - - char* leafName = newFile.GetLeafName(); - newFile.Rename(leafName); - delete [] leafName; - } - - return nsInstall::SUCCESS; -} - - void* nsInstallPatch::HashFilePath(const nsFilePath& aPath) { diff --git a/mozilla/xpinstall/src/nsInstallPatch.h b/mozilla/xpinstall/src/nsInstallPatch.h index 2b0e864ec62..c422245bce9 100644 --- a/mozilla/xpinstall/src/nsInstallPatch.h +++ b/mozilla/xpinstall/src/nsInstallPatch.h @@ -73,8 +73,6 @@ class nsInstallPatch : public nsInstallObject PRInt32 NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patchfile, nsFileSpec **newFile); - PRInt32 NativeReplace(nsFileSpec& target, nsFileSpec& tempFile); - PRInt32 NativeDeleteFile(nsFileSpec* doomedFile); void* HashFilePath(const nsFilePath& aPath); }; diff --git a/mozilla/xpinstall/src/nsSoftwareUpdate.cpp b/mozilla/xpinstall/src/nsSoftwareUpdate.cpp index 370ff8f545c..3486ffc344d 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdate.cpp +++ b/mozilla/xpinstall/src/nsSoftwareUpdate.cpp @@ -146,7 +146,7 @@ nsSoftwareUpdate::Startup() /* Perform Scheduled Tasks */ /***************************************/ - +#if 0 PR_CreateThread(PR_USER_THREAD, PerformScheduledTasks, nsnull, @@ -154,7 +154,8 @@ nsSoftwareUpdate::Startup() PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0); - +#endif + PerformScheduledTasks(nsnull); return NS_OK; }