diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-20 01:16:23 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-20 01:16:23 +0000 |
commit | 02ee34a9daa91fd125b9f9a48ca56502c8d1d36c (patch) | |
tree | 607ac680d8d8d8b39348d8415677e9813d440737 | |
parent | c328da8db8cb5c8d9366874c6e23533e9fa82c7e (diff) | |
download | chromium_src-02ee34a9daa91fd125b9f9a48ca56502c8d1d36c.zip chromium_src-02ee34a9daa91fd125b9f9a48ca56502c8d1d36c.tar.gz chromium_src-02ee34a9daa91fd125b9f9a48ca56502c8d1d36c.tar.bz2 |
Fix AmountOfFreeDiskSpace to be able to differentiate an error
from a full disk.
Review URL: http://codereview.chromium.org/4003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2431 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/sys_info.h | 3 | ||||
-rw-r--r-- | base/sys_info_posix.cc | 2 | ||||
-rw-r--r-- | base/sys_info_win.cc | 12 | ||||
-rw-r--r-- | net/disk_cache/mem_backend_impl.cc | 2 |
4 files changed, 13 insertions, 6 deletions
diff --git a/base/sys_info.h b/base/sys_info.h index 00436f5..3d6a16a6 100644 --- a/base/sys_info.h +++ b/base/sys_info.h @@ -24,7 +24,8 @@ class SysInfo { return static_cast<int>(AmountOfPhysicalMemory() / 1024 / 1024); } - // Return the available disk space in bytes on the volume containing |path|. + // Return the available disk space in bytes on the volume containing |path|, + // or -1 on failure. static int64 AmountOfFreeDiskSpace(const std::wstring& path); }; diff --git a/base/sys_info_posix.cc b/base/sys_info_posix.cc index 541a424..28c8bd6 100644 --- a/base/sys_info_posix.cc +++ b/base/sys_info_posix.cc @@ -65,7 +65,7 @@ int64 SysInfo::AmountOfPhysicalMemory() { int64 SysInfo::AmountOfFreeDiskSpace(const std::wstring& path) { struct statvfs stats; if (statvfs(WideToUTF8(path).c_str(), &stats) != 0) { - return 0; + return -1; } return static_cast<int64>(stats.f_bavail) * stats.f_frsize; } diff --git a/base/sys_info_win.cc b/base/sys_info_win.cc index a90f7b9..2d3c203 100644 --- a/base/sys_info_win.cc +++ b/base/sys_info_win.cc @@ -26,16 +26,22 @@ int64 SysInfo::AmountOfPhysicalMemory() { return 0; } - return static_cast<int64>(memory_info.ullTotalPhys); + int64 rv = static_cast<int64>(memory_info.ullTotalPhys); + if (rv < 0) + rv = kint64max; + return rv; } // static int64 SysInfo::AmountOfFreeDiskSpace(const std::wstring& path) { ULARGE_INTEGER available, total, free; if (!GetDiskFreeSpaceExW(path.c_str(), &available, &total, &free)) { - return 0; + return -1; } - return static_cast<int64>(available.QuadPart); + int64 rv = static_cast<int64>(available.QuadPart); + if (rv < 0) + rv = kint64max; + return rv; } } // namespace base diff --git a/net/disk_cache/mem_backend_impl.cc b/net/disk_cache/mem_backend_impl.cc index cf4a411..4180a9d 100644 --- a/net/disk_cache/mem_backend_impl.cc +++ b/net/disk_cache/mem_backend_impl.cc @@ -43,7 +43,7 @@ bool MemBackendImpl::Init() { int64 total_memory = base::SysInfo::AmountOfPhysicalMemory(); - if (total_memory < 0) { + if (total_memory <= 0) { max_size_ = kDefaultCacheSize; return true; } |