filesystem.hpp #1

  • //
  • guest/
  • ShadauxCat/
  • Sprawl/
  • Mainline/
  • filesystem/
  • filesystem.hpp
  • View
  • Commits
  • Open Download .zip Download (2 KB)
#pragma once

#include "../string/String.hpp"

namespace sprawl
{
	namespace path
	{
		char Separator();

		String AbsolutePath(String const& path);
		String Basename(String const& path);
		String Dirname(String const& path);

		bool Exists(String const& path);
		bool LExists(String const& path);

		String ExpandUser(String const& path);
		String ExpandVars(String const& path);

		int64_t GetAccessTime(String const& path);
		int64_t GetModificationTime(String const& path);
		int64_t GetCreationTime(String const& path);
		int64_t GetSize(String const& path);

		bool IsAbsolute(String const& path);
		bool IsFile(String const& path);
		bool IsDirectory(String const& path);
		bool IsLink(String const& path);
		bool IsMountPoint(String const& path);

		template<typename T>
		String Join(StringBuilder builder, T const& lastItem);

		template<typename T, typename... Params>
		String Join(StringBuilder builder, T const& nextItem, Params const&... params);

		template<typename T, typename... Params>
		String Join(T const& begin, Params const&... params);

		String NormCase(String const& path);
		String NormPath(String const& path);
		String RealPath(String const& path);
		String RelativePath(String const& path, String const& relativeTo = StringLiteral("./"));

		bool SameFile(String const& path1, String const& path2);

		///@todo - Split, walk, commonprefix
	}
	namespace filesystem
	{
		void Chdir(String const& path);
		String GetCwd();

		enum class RelativeTo
		{
			Beginning,
			CurrentPosition,
			End,
		};

		class File
		{
		public:
			void Close();
			void Sync();
			void Flush();
			int FileNo();
			bool IsATTY();

			String const& Read(int numBytes = -1);
			String const& ReadLine(int numBytes = -1);

			void Seek(int offset, RelativeTo relativeTo);
			int Tell();

			void Truncate(int size = -1);

			void Write(String const& str);

			bool IsClosed();
			String const& Mode();
		};

		File Open(String const& path);

		/// @todo - access(), chflags

		bool Chmod(String const& path, int mode);
		bool Mkdir(String const& path, int mode);
		bool MakeDirs(String const& path, int mode);
		bool Remove(String const& path);
		bool RemoveDirs(String const& path);
		bool Rename(String const& path, String const& newName);
		bool Renames(String const& path, String const& newName);
		bool RmDir(String const& path);
	}
}
# Change User Description Committed
#6 16131 ShadauxCat - Exposed FILE* object in sprawl::filesystem::File
- Added ability to specify flush behavior for custom handlers via std::function (interesting note - apparently with optimization enabled, calls to std::function can execute faster than virtual function calls)
- Threads that destruct with no Join() after exiting with an uncaught exception will terminate with an error message rather than swallowing the exception and letting it disappear

#review-16132
#5 14822 ShadauxCat Last batch of filesystem code for now, added MakeSymlink and GetPid, removed other todo functions for the time being.
Also fixed some bugs:

-Linux IsLink() implementation not using lstat = broken
-File::IsClosed() would crash if file were created via default constructor or null handle
-Remove() and RmDir() on Windows were inconsistent with Linux - in Linux all symlinks are removed with Remove() even if they point to directories. Forced windows to work the same way.
-Asked RmTree to please not descend into symbolic links to directories, but just to remove them, thanks.
-Removed starting \\?\ from result of RealPath() on Windows
-Fixed IsFile() on Windows just not working - assuming anything that's not a directory is a file now.
-Fixed StringBuilder only printing the first character if you passed it type char* instead of type char const*

#review-14823
#4 14816 ShadauxCat Filled in some more filesystem functions, added appropriate unit tests.
Only a few remain.

#review-14817
#3 14781 ShadauxCat -Finished path library
-Added some more functionality to filesystem library
-Added a few more unit tests, still more needed for path

#review-14782
#2 14761 ShadauxCat First drop of code for sprawl::filesystem and sprawl::path.
Library will continue to grow.

Also fixed a warning on linux.

#review-14762
#1 12508 ShadauxCat -Added threading library.
Currently only functional for Linux; Windows will fail to link. (I will fix this soon.)
-Fixed missing move and copy constructors in List and ForwardList
-Fixed broken move constructor in HashMap
-Fixed missing const get() in HashMap
-Fixed broken operator-> in ListIterator
-Added sprawl::noncopyable
-Added sketch headers for filesystem library
-Made StringLiteral hashable, added special hashes for pointers and integers in murmur3
-Fixed compiler warning in async_network
-Updated memory allocators to use new threading library for mutexes
-Added accessibility to sprawl::StringLiteral to be able toa ccess its pointer and length and perform pointer comparisons

#review-12504