[PATCH] D18467: Add disk_space() to llvm::fs
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 25 20:00:12 PDT 2016
> On Mar 25, 2016, at 7:51 PM, Rafael EspĂndola <rafael.espindola at gmail.com> wrote:
>
>
> On Mar 25, 2016 12:42 PM, "Mehdi Amini" <mehdi.amini at apple.com <mailto:mehdi.amini at apple.com>> wrote:
> >
> > I thought about it but the rest of the file is using std::error_code as a return. Do we want to introduce a discrepancy here?
> >
>
> I would prefer it, yes. Otherwise it is hard to migrate to newer APIs.
>
I'd convert the whole file in one single commit. But I see the point about not adding more interface to convert later. Will update.
--
Mehdi
> Cheers,
> Rafael
>
>
> >> On Mar 25, 2016, at 9:41 AM, Rafael EspĂndola <rafael.espindola at gmail.com <mailto:rafael.espindola at gmail.com>> wrote:
> >>
> >> Can you return an ErrorOr or Expected?
> >>
> >> On Mar 24, 2016 8:17 PM, "Mehdi AMINI via llvm-commits" <llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>> wrote:
> >>>
> >>> joker.eph created this revision.
> >>> joker.eph added reviewers: bruno, silvas.
> >>> joker.eph added a subscriber: llvm-commits.
> >>> Herald added subscribers: srhines, danalbert, tberghammer.
> >>>
> >>> Adapted from Boost::filesystem.
> >>>
> >>> http://reviews.llvm.org/D18467 <http://reviews.llvm.org/D18467>
> >>>
> >>> Files:
> >>> include/llvm/Support/FileSystem.h
> >>> lib/Support/Unix/Path.inc
> >>> lib/Support/Windows/Path.inc
> >>>
> >>> Index: lib/Support/Windows/Path.inc
> >>> ===================================================================
> >>> --- lib/Support/Windows/Path.inc
> >>> +++ lib/Support/Windows/Path.inc
> >>> @@ -151,6 +151,19 @@
> >>> return UniqueID(VolumeSerialNumber, FileID);
> >>> }
> >>>
> >>> +std::error_code disk_space(const Twine Path, space_info &SpaceInfo) {
> >>> + PULARGE_INTEGER avail, total, free;
> >>> + if (!::GetDiskFreeSpaceExW(Path.str().c_str(), &avail, &total, &free))
> >>> + return mapWindowsError(::GetLastError());
> >>> + SpaceInfo.capacity = (static_cast<uint64_t>(total.HighPart) << 32)
> >>> + + total.LowPart;
> >>> + SpaceInfo.free = (static_cast<uint64_t>(free.HighPart) << 32)
> >>> + + free.LowPart;
> >>> + SpaceInfo.available = (static_cast<uint64_t>(avail.HighPart) << 32)
> >>> + + avail.LowPart;
> >>> + return std::error_code();
> >>> +}
> >>> +
> >>> TimeValue file_status::getLastAccessedTime() const {
> >>> ULARGE_INTEGER UI;
> >>> UI.LowPart = LastAccessedTimeLow;
> >>> Index: lib/Support/Unix/Path.inc
> >>> ===================================================================
> >>> --- lib/Support/Unix/Path.inc
> >>> +++ lib/Support/Unix/Path.inc
> >>> @@ -60,6 +60,24 @@
> >>> # define PATH_MAX 4096
> >>> #endif
> >>>
> >>> +#include <sys/types.h>
> >>> +#if !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__ANDROID__)
> >>> +# include <sys/statvfs.h>
> >>> +# define STATVFS statvfs
> >>> +# define STATVFS_F_FRSIZE(vfs) vfs.f_frsize
> >>> +#else
> >>> +# ifdef __OpenBSD__
> >>> +# include <sys/param.h>
> >>> +# elif defined(__ANDROID__)
> >>> +# include <sys/vfs.h>
> >>> +# else
> >>> +# include <sys/mount.h>
> >>> +# endif
> >>> +# define STATVFS statfs
> >>> +# define STATVFS_F_FRSIZE(vfs) static_cast<uint64_t>(vfs.f_bsize)
> >>> +#endif
> >>> +
> >>> +
> >>> using namespace llvm;
> >>>
> >>> namespace llvm {
> >>> @@ -190,6 +208,18 @@
> >>> return UniqueID(fs_st_dev, fs_st_ino);
> >>> }
> >>>
> >>> +std::error_code disk_space(const Twine Path, space_info &SpaceInfo) {
> >>> + struct STATVFS Vfs;
> >>> + if(::STATVFS(Path.str().c_str(), &Vfs))
> >>> + return std::error_code(errno, std::generic_category());
> >>> + SpaceInfo.capacity =
> >>> + static_cast<uint64_t>(Vfs.f_blocks)* STATVFS_F_FRSIZE(Vfs);
> >>> + SpaceInfo.free = static_cast<uint64_t>(Vfs.f_bfree)* STATVFS_F_FRSIZE(Vfs);
> >>> + SpaceInfo.available =
> >>> + static_cast<uint64_t>(Vfs.f_bavail)* STATVFS_F_FRSIZE(Vfs);
> >>> + return std::error_code();
> >>> +}
> >>> +
> >>> std::error_code current_path(SmallVectorImpl<char> &result) {
> >>> result.clear();
> >>>
> >>> Index: include/llvm/Support/FileSystem.h
> >>> ===================================================================
> >>> --- include/llvm/Support/FileSystem.h
> >>> +++ include/llvm/Support/FileSystem.h
> >>> @@ -647,6 +647,15 @@
> >>>
> >>> std::error_code getUniqueID(const Twine Path, UniqueID &Result);
> >>>
> >>> +/// @brief Get disk space usage information.
> >>> +///
> >>> +/// @param Path Input path.
> >>> +/// @param SpaceInfo Set to the capacity, free, and available space on the
> >>> +/// device \a Path is on.
> >>> +/// @results errc::success if result has been successfully set, otherwise a
> >>> +/// platform specific error_code.
> >>> +std::error_code disk_space(const Twine Path, space_info &SpaceInfo);
> >>> +
> >>> /// This class represents a memory mapped file. It is based on
> >>> /// boost::iostreams::mapped_file.
> >>> class mapped_file_region {
> >>>
> >>>
> >>>
> >>> _______________________________________________
> >>> llvm-commits mailing list
> >>> llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>
> >>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits>
> >>>
> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160325/47417f63/attachment.html>
More information about the llvm-commits
mailing list