r/sr=alecf
Patch from Alfred Keyser - optimize time stuff in nsZipArchive
This commit is contained in:
mkaply%us.ibm.com 2003-07-15 22:18:04 +00:00
Родитель f8a4e98ca2
Коммит 10417bd5eb
4 изменённых файлов: 25 добавлений и 91 удалений

Просмотреть файл

@ -284,7 +284,14 @@ nsJAR::Extract(const char *zipEntry, nsIFile* outFile)
}
#endif
RestoreModTime(item, outFile); // non-fatal if this fails, ignore errors
PRTime prtime = item->GetModTime();
// nsIFile needs usecs.
PRTime conversion = LL_ZERO;
PRTime newTime = LL_ZERO;
LL_I2L(conversion, PR_USEC_PER_MSEC);
LL_DIV(newTime, prtime, conversion);
// non-fatal if this fails, ignore errors
outFile->SetLastModifiedTime(newTime);
}
return ziperr2nsresult(err);
@ -865,34 +872,6 @@ void nsJAR::ReportError(const char* aFilename, PRInt16 errorCode)
#endif
}
nsresult
nsJAR::RestoreModTime(nsZipItem *aItem, nsIFile *aExtractedFile)
{
if (!aItem || !aExtractedFile)
return NS_ERROR_NULL_POINTER;
char *timestr;
PRTime prtime;
nsresult rv = NS_OK;
timestr = aItem->GetModTime();
if (timestr)
{
if (PR_SUCCESS == PR_ParseTimeString(timestr, PR_FALSE, &prtime))
{
PRTime conversion = LL_ZERO;
PRTime newTime = LL_ZERO;
LL_I2L(conversion, PR_USEC_PER_MSEC);
LL_DIV(newTime, prtime, conversion);
// nsIFile needs usecs.
rv = aExtractedFile->SetLastModifiedTime(newTime);
}
JAR_NULLFREE(timestr);
}
return rv;
}
nsresult nsJAR::CalculateDigest(nsISignatureVerifier* verifier,
const char* aInBuf, PRUint32 aLen,

Просмотреть файл

@ -128,7 +128,6 @@ class nsJAR : public nsIZipReader, public nsIJAR
nsresult VerifyEntry(nsISignatureVerifier* verifier,
nsJARManifestItem* aEntry, const char* aEntryData,
PRUint32 aLen);
nsresult RestoreModTime(nsZipItem *aItem, nsIFile *aExtractedFile);
nsresult CalculateDigest(nsISignatureVerifier* verifier,
const char* aInBuf, PRUint32 aInBufLen,

Просмотреть файл

@ -41,6 +41,7 @@
#include "prio.h"
#include "plstr.h"
#include "prlog.h"
#include "prprf.h"
#define ZFILE_CREATE PR_WRONLY | PR_CREATE_FILE
#define READTYPE PRInt32
#include "zlib.h"
@ -1850,67 +1851,21 @@ static PRBool IsSymlink(PRUint32 ext_attr)
return (((ext_attr>>16) & S_IFMT) == S_IFLNK) ? PR_TRUE : PR_FALSE;
}
/*
* d o s d a t e
*
* Based on standard MS-DOS format date.
* Tweaked to be Y2K compliant and NSPR friendly.
*/
static void dosdate (char *aOutDateStr, PRUint16 aDate)
{
PRUint16 y2kCompliantYear = (aDate >> 9) + 1980;
sprintf (aOutDateStr, "%02d/%02d/%02d",
((aDate >> 5) & 0x0F), (aDate & 0x1F), y2kCompliantYear);
return;
}
/*
* d o s t i m e
*
* Standard MS-DOS format time.
*/
static void dostime (char *aOutTimeStr, PRUint16 aTime)
{
sprintf (aOutTimeStr, "%02d:%02d",
((aTime >> 11) & 0x1F), ((aTime >> 5) & 0x3F));
return;
}
char *
#ifndef STANDALONE
PRTime
nsZipItem::GetModTime()
{
char *timestr; /* e.g. 21:07 */
char *datestr; /* e.g. 06/20/1995 */
char *nsprstr; /* e.g. 06/20/1995 21:07 */
/* NSPR bug parsing dd/mm/yyyy hh:mm */
/* so we use mm/dd/yyyy hh:mm */
char buffer[17];
timestr = (char *) PR_Malloc(6 * sizeof(char));
datestr = (char *) PR_Malloc(11 * sizeof(char));
nsprstr = (char *) PR_Malloc(17 * sizeof(char));
if (!timestr || !datestr || !nsprstr)
{
PR_FREEIF(timestr);
PR_FREEIF(datestr);
PR_FREEIF(nsprstr);
return 0;
}
PRUint16 aDate = this->date;
PRUint16 aTime = this->time;
memset(timestr, 0, 6);
memset(datestr, 0, 11);
memset(nsprstr, 0, 17);
PR_snprintf(buffer, sizeof(buffer), "%02d/%02d/%04d %02d:%02d",
((aDate >> 5) & 0x0F), (aDate & 0x1F), (aDate >> 9) + 1980,
((aTime >> 11) & 0x1F), ((aTime >> 5) & 0x3F));
dosdate(datestr, this->date);
dostime(timestr, this->time);
sprintf(nsprstr, "%s %s", datestr, timestr);
PR_FREEIF(timestr);
PR_FREEIF(datestr);
return nsprstr;
PRTime result;
PR_ParseTimeString(buffer, PR_FALSE, &result);
return result;
}
#endif

Просмотреть файл

@ -121,16 +121,17 @@ public:
PRUint8 compression;
PRUint8 flags;
#ifndef STANDALONE
/**
* GetModTime
*
* Utility to get an NSPR-friendly formatted string
* representing the last modified time of this item.
*
* @return nsprstr an NSPR-friendly string representation
* of the modification time
* @return nsprstr The modification time in PRTime
*/
char *GetModTime();
PRTime GetModTime();
#endif
nsZipItem();
~nsZipItem();