Bug 103726 - ftp directory listings not reflecting file changes on reload

r=dougt, sr=darin
This commit is contained in:
bbaetz%student.usyd.edu.au 2002-02-14 00:09:37 +00:00
Родитель bd81c661f6
Коммит 36130a4a04
3 изменённых файлов: 80 добавлений и 5 удалений

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

@ -1389,7 +1389,7 @@ nsFtpState::R_retr() {
if ((mResponseCode/100 == 5) && (mServerType != FTP_OS2_TYPE)) {
mRETRFailed = PR_TRUE;
// We need to kill off the existing connection - see bug 101128
mDRequestForwarder->RetryConnection();
nsCOMPtr<nsISocketTransport> st = do_QueryInterface(mDPipe);
@ -1794,6 +1794,80 @@ nsFtpState::SetLoadFlags(nsLoadFlags aLoadFlags)
return NS_ERROR_NOT_IMPLEMENTED;
}
// This really really needs to be somewhere else
static inline PRUint32
PRTimeToSeconds(PRTime t_usec)
{
PRTime usec_per_sec;
PRUint32 t_sec;
LL_I2L(usec_per_sec, PR_USEC_PER_SEC);
LL_DIV(t_usec, t_usec, usec_per_sec);
LL_L2I(t_sec, t_usec);
return t_sec;
}
#define NowInSeconds() PRTimeToSeconds(PR_Now())
PRUint32 nsFtpState::mSessionStartTime = NowInSeconds();
/* Is this cache entry valid to use for reading?
* Since we make up an expiration time for ftp, use the following rules:
* (see bug 103726)
*
* LOAD_FROM_CACHE : always use cache entry, even if expired
* LOAD_BYPASS_CACHE : overwrite cache entry
* LOAD_NORMAL|VALIDATE_ALWAYS : overwrite cache entry
* LOAD_NORMAL : honor expiration time
* LOAD_NORMAL|VALIDATE_ONCE_PER_SESSION : overwrite cache entry if first access
* this session, otherwise use cache entry
* even if expired.
* LOAD_NORMAL|VALIDATE_NEVER : always use cache entry, even if expired
*
* Note that in theory we could use the mdtm time on the directory
* In practice, the lack of a timezone plus the general lack of support for that
* on directories means that its not worth it, I suspect. Revisit if we start
* caching files - bbaetz
*/
PRBool
nsFtpState::CanReadEntry()
{
nsCacheAccessMode access;
nsresult rv = mCacheEntry->GetAccessGranted(&access);
if (NS_FAILED(rv)) return PR_FALSE;
// If I'm not granted read access, then I can't reuse it...
if (!(access & nsICache::ACCESS_READ))
return PR_FALSE;
nsLoadFlags flags;
rv = mChannel->GetLoadFlags(&flags);
if (NS_FAILED(rv)) return PR_FALSE;
if (flags & LOAD_FROM_CACHE)
return PR_TRUE;
if (flags & LOAD_BYPASS_CACHE)
return PR_FALSE;
if (flags & VALIDATE_ALWAYS)
return PR_FALSE;
PRUint32 time;
if (flags & VALIDATE_ONCE_PER_SESSION) {
rv = mCacheEntry->GetLastModified(&time);
if (NS_FAILED(rv)) return PR_FALSE;
return (mSessionStartTime > time);
}
if (flags & VALIDATE_NEVER)
return PR_TRUE;
// OK, now we just check the expiration time as usual
rv = mCacheEntry->GetExpirationTime(&time);
if (NS_FAILED(rv)) return rv;
return (NowInSeconds() <= time);
}
nsresult
nsFtpState::Init(nsIFTPChannel* aChannel,
nsIPrompt* aPrompter,
@ -1830,9 +1904,7 @@ nsFtpState::Init(nsIFTPChannel* aChannel,
if (NS_FAILED(rv)) return rv;
if (mCacheEntry) {
nsCacheAccessMode access;
mCacheEntry->GetAccessGranted(&access);
if (access & nsICache::ACCESS_READ) {
if (CanReadEntry()) {
// XXX - all this code assumes that we only cache directories
// If we start caching files, this needs to be updated

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

@ -159,6 +159,7 @@ private:
nsresult SendFTPCommand(nsCString& command);
nsresult BuildStreamConverter(nsIStreamListener** convertStreamListener);
nsresult SetContentType();
PRBool CanReadEntry();
///////////////////////////////////
// Private members
@ -216,6 +217,8 @@ private:
nsCOMPtr<nsIPrompt> mPrompter;
nsCOMPtr<nsIFTPEventSink> mFTPEventSink;
nsCOMPtr<nsIAuthPrompt> mAuthPrompter;
static PRUint32 mSessionStartTime;
char *mIPv6ServerAddress; // Server IPv6 address; null if server not IPv6

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

@ -208,7 +208,7 @@ nsFtpProtocolHandler::NewProxiedChannel(nsIURI* url, nsIProxyInfo* proxyInfo, ns
getter_AddRefs(mCacheSession));
if (mCacheSession)
rv = mCacheSession->SetDoomEntriesIfExpired(PR_TRUE);
rv = mCacheSession->SetDoomEntriesIfExpired(PR_FALSE);
rv = channel->Init(url, proxyInfo, mCacheSession);
if (NS_FAILED(rv)) {