Bug 240257 directory listings show wrong sizes for files > 4 GB

changes nsIDirIndex to use PRInt64
r=darin sr=bryner
This commit is contained in:
cbiesinger%web.de 2004-04-18 13:20:54 +00:00
Родитель bd2796f514
Коммит 258c6de73a
8 изменённых файлов: 28 добавлений и 20 удалений

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

@ -350,9 +350,6 @@ nsDirectoryIndexStream::Read(char* aBuf, PRUint32 aCount, PRUint32* aReadCount)
PRInt64 fileSize = LL_Zero(); PRInt64 fileSize = LL_Zero();
current->GetFileSize( &fileSize ); current->GetFileSize( &fileSize );
PROffset32 fileInfoSize;
LL_L2I( fileInfoSize,fileSize );
PRInt64 tmpTime = LL_Zero(); PRInt64 tmpTime = LL_Zero();
PRInt64 fileInfoModifyTime = LL_Zero(); PRInt64 fileInfoModifyTime = LL_Zero();
current->GetLastModifiedTime( &tmpTime ); current->GetLastModifiedTime( &tmpTime );
@ -394,7 +391,7 @@ nsDirectoryIndexStream::Read(char* aBuf, PRUint32 aCount, PRUint32* aReadCount)
} }
// The "content-length" field // The "content-length" field
mBuf.AppendInt(fileInfoSize, 10); mBuf.AppendInt(fileSize, 10);
mBuf.Append(' '); mBuf.Append(' ');
// The "last-modified" field // The "last-modified" field

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

@ -99,6 +99,6 @@ nsDirIndex::SetDescription(const PRUnichar* aDescription) {
return NS_OK; return NS_OK;
} }
NS_IMPL_GETSET(nsDirIndex, Size, PRUint32, mSize) NS_IMPL_GETSET(nsDirIndex, Size, PRInt64, mSize)
NS_IMPL_GETSET(nsDirIndex, LastModified, PRInt64, mLastModified) NS_IMPL_GETSET(nsDirIndex, LastModified, PRInt64, mLastModified)

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

@ -43,7 +43,7 @@
class nsDirIndex : public nsIDirIndex { class nsDirIndex : public nsIDirIndex {
public: public:
nsDirIndex(); nsDirIndex();
virtual ~nsDirIndex(); ~nsDirIndex();
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSIDIRINDEX NS_DECL_NSIDIRINDEX
@ -53,6 +53,6 @@ protected:
nsXPIDLCString mContentType; nsXPIDLCString mContentType;
nsXPIDLCString mLocation; nsXPIDLCString mLocation;
nsString mDescription; nsString mDescription;
PRUint32 mSize; PRInt64 mSize;
PRInt64 mLastModified; PRInt64 mLastModified;
}; };

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

@ -42,6 +42,8 @@
/* This parsing code originally lived in xpfe/components/directory/ - bbaetz */ /* This parsing code originally lived in xpfe/components/directory/ - bbaetz */
#include "prprf.h"
#include "nsDirIndexParser.h" #include "nsDirIndexParser.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsDirIndex.h" #include "nsDirIndex.h"
@ -327,8 +329,12 @@ nsDirIndexParser::ParseData(nsIDirIndex *aIdx, char* aDataStr) {
break; break;
case FIELD_CONTENTLENGTH: case FIELD_CONTENTLENGTH:
{ {
unsigned long len = strtoul(value,NULL,10); PRInt64 len;
aIdx->SetSize(len); PRInt32 status = PR_sscanf(value, "%lld", &len);
if (status == 1)
aIdx->SetSize(len);
else
aIdx->SetSize(LL_INIT(0, -1)); // -1 means unknown
} }
break; break;
case FIELD_LASTMODIFIED: case FIELD_LASTMODIFIED:

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

@ -47,6 +47,7 @@
#include "nsURLHelper.h" #include "nsURLHelper.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsIPlatformCharset.h" #include "nsIPlatformCharset.h"
#include "nsInt64.h"
NS_IMPL_THREADSAFE_ISUPPORTS4(nsIndexedToHTML, NS_IMPL_THREADSAFE_ISUPPORTS4(nsIndexedToHTML,
nsIDirIndexListener, nsIDirIndexListener,
@ -546,10 +547,10 @@ nsIndexedToHTML::OnIndexAvailable(nsIRequest *aRequest,
pushBuffer.Append(NS_LITERAL_STRING("</a></td>\n <td>")); pushBuffer.Append(NS_LITERAL_STRING("</a></td>\n <td>"));
PRUint32 size; PRInt64 size;
aIndex->GetSize(&size); aIndex->GetSize(&size);
if (size != PRUint32(-1) && if (size != LL_INIT(0, -1) &&
type != nsIDirIndex::TYPE_DIRECTORY && type != nsIDirIndex::TYPE_DIRECTORY &&
type != nsIDirIndex::TYPE_SYMLINK) { type != nsIDirIndex::TYPE_SYMLINK) {
nsAutoString sizeString; nsAutoString sizeString;
@ -596,12 +597,13 @@ nsIndexedToHTML::OnIndexAvailable(nsIRequest *aRequest,
return FormatInputStream(aRequest, aCtxt, pushBuffer); return FormatInputStream(aRequest, aCtxt, pushBuffer);
} }
void nsIndexedToHTML::FormatSizeString(PRUint32 inSize, nsString& outSizeString) void nsIndexedToHTML::FormatSizeString(PRInt64 inSize, nsString& outSizeString)
{ {
nsInt64 size(inSize);
outSizeString.Truncate(); outSizeString.Truncate();
if (inSize > 0) { if (size > nsInt64(0)) {
// round up to the nearest Kilobyte // round up to the nearest Kilobyte
PRUint32 upperSize = (inSize + 1023) / 1024; PRInt64 upperSize = (size + nsInt64(1023)) / nsInt64(1024);
outSizeString.AppendInt(upperSize); outSizeString.AppendInt(upperSize);
outSizeString.Append(NS_LITERAL_STRING(" KB")); outSizeString.Append(NS_LITERAL_STRING(" KB"));
} }

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

@ -75,7 +75,7 @@ public:
protected: protected:
void FormatSizeString(PRUint32 inSize, nsString& outSizeString); void FormatSizeString(PRInt64 inSize, nsString& outSizeString);
nsresult FormatInputStream(nsIRequest* aRequest, nsISupports *aContext, const nsAString &aBuffer); nsresult FormatInputStream(nsIRequest* aRequest, nsISupports *aContext, const nsAString &aBuffer);
protected: protected:

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

@ -92,14 +92,14 @@ interface nsIDirIndex : nsISupports
/** /**
* File size, with -1 meaning "unknown" * File size, with -1 meaning "unknown"
*/ */
attribute unsigned long size; attribute long long size;
/** /**
* Last-modified time in seconds-since-epoch. * Last-modified time in seconds-since-epoch.
* -1 means unknown - this is valid, because there were no * -1 means unknown - this is valid, because there were no
* ftp servers in 1969 * ftp servers in 1969
*/ */
attribute long long lastModified; attribute PRTime lastModified;
}; };
%{C++ %{C++

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

@ -477,12 +477,15 @@ nsHTTPIndex::OnIndexAvailable(nsIRequest* aRequest, nsISupports *aContext,
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
// contentlength // contentlength
PRUint32 size; PRInt64 size;
rv = aIndex->GetSize(&size); rv = aIndex->GetSize(&size);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
if (size != PRUint32(-1)) { if (size != LL_INIT(0, -1)) {
PRInt32 intSize;
LL_L2I(intSize, size);
// XXX RDF should support 64 bit integers (bug 240160)
nsCOMPtr<nsIRDFInt> val; nsCOMPtr<nsIRDFInt> val;
rv = mDirRDF->GetIntLiteral(size, getter_AddRefs(val)); rv = mDirRDF->GetIntLiteral(intSize, getter_AddRefs(val));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = Assert(entry, kNC_ContentLength, val, PR_TRUE); rv = Assert(entry, kNC_ContentLength, val, PR_TRUE);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;