Newer
Older
dub_jkp / source / dub / internal / io / realfs.d
  1. /*******************************************************************************
  2.  
  3. An implementation of `Filesystem` using vibe.d functions
  4.  
  5. *******************************************************************************/
  6.  
  7. module dub.internal.io.realfs;
  8.  
  9. public import dub.internal.io.filesystem;
  10.  
  11. /// Ditto
  12. public final class RealFS : Filesystem {
  13. static import dub.internal.vibecompat.core.file;
  14. static import std.file;
  15.  
  16. ///
  17. private NativePath path_;
  18.  
  19. ///
  20. public this (NativePath cwd = NativePath(std.file.getcwd()))
  21. scope @safe pure nothrow @nogc
  22. {
  23. this.path_ = cwd;
  24. }
  25.  
  26. public override NativePath getcwd () const scope
  27. {
  28. return this.path_;
  29. }
  30.  
  31. ///
  32. protected override bool existsDirectory (in NativePath path) const scope
  33. {
  34. return dub.internal.vibecompat.core.file.existsDirectory(path);
  35. }
  36.  
  37. /// Ditto
  38. protected override void mkdir (in NativePath path) scope
  39. {
  40. dub.internal.vibecompat.core.file.ensureDirectory(path);
  41. }
  42.  
  43. /// Ditto
  44. protected override bool existsFile (in NativePath path) const scope
  45. {
  46. return dub.internal.vibecompat.core.file.existsFile(path);
  47. }
  48.  
  49. /// Ditto
  50. protected override void writeFile (in NativePath path, const(ubyte)[] data)
  51. scope
  52. {
  53. return dub.internal.vibecompat.core.file.writeFile(path, data);
  54. }
  55.  
  56. /// Reads a file, returns the content as `ubyte[]`
  57. public override ubyte[] readFile (in NativePath path) const scope
  58. {
  59. return cast(ubyte[]) std.file.read(path.toNativeString());
  60. }
  61.  
  62. /// Ditto
  63. protected override string readText (in NativePath path) const scope
  64. {
  65. return dub.internal.vibecompat.core.file.readText(path);
  66. }
  67.  
  68. /// Ditto
  69. protected override IterateDirDg iterateDirectory (in NativePath path) scope
  70. {
  71. return dub.internal.vibecompat.core.file.iterateDirectory(path);
  72. }
  73.  
  74. /// Ditto
  75. protected override void removeFile (in NativePath path, bool force = false) scope
  76. {
  77. return std.file.remove(path.toNativeString());
  78. }
  79.  
  80. ///
  81. public override void removeDir (in NativePath path, bool force = false)
  82. {
  83. if (force)
  84. std.file.rmdirRecurse(path.toNativeString());
  85. else
  86. std.file.rmdir(path.toNativeString());
  87. }
  88.  
  89. /// Ditto
  90. protected override void setTimes (in NativePath path, in SysTime accessTime,
  91. in SysTime modificationTime)
  92. {
  93. std.file.setTimes(
  94. path.toNativeString(), accessTime, modificationTime);
  95. }
  96.  
  97. /// Ditto
  98. protected override void setAttributes (in NativePath path, uint attributes)
  99. {
  100. std.file.setAttributes(path.toNativeString(), attributes);
  101. }
  102. }