public static int MakeDirectory(ConversionStorage <MutableString> /*!*/ toPath, RubyClass /*!*/ self, object dirname, [Optional] object permissions) { var platform = self.Context.Platform; string strDir = self.Context.DecodePath(Protocols.CastToPath(toPath, dirname)); if (platform.FileExists(strDir) || platform.DirectoryExists(strDir)) { throw RubyExceptions.CreateEEXIST(strDir); } string containingDir = platform.GetDirectoryName(strDir); if (!String.IsNullOrEmpty(containingDir) && !platform.DirectoryExists(containingDir)) { throw RubyExceptions.CreateENOENT("No such file or directory - {0}", containingDir); } try { platform.CreateDirectory(strDir); } catch (Exception ex) { throw ToRubyException(ex, strDir, DirectoryOperation.Create); } return(0); }
public static int RemoveDirectory(ConversionStorage <MutableString> /*!*/ toPath, RubyClass /*!*/ self, object dirname) { string strDir = self.Context.DecodePath(Protocols.CastToPath(toPath, dirname)); try { self.Context.Platform.DeleteDirectory(strDir, false); } catch (Exception ex) { throw ToRubyException(ex, strDir, DirectoryOperation.Delete); } return(0); }
public static object Open(ConversionStorage <MutableString> /*!*/ toPath, BlockParam block, RubyClass /*!*/ self, object dirname) { RubyDir rd = new RubyDir(self, Protocols.CastToPath(toPath, dirname)); try { object result; block.Yield(rd, out result); return(result); } finally { Close(rd); } }
public static object NullableSize(ConversionStorage <MutableString> /*!*/ toPath, RubyModule /*!*/ self, object path) { FileSystemInfo fsi; if (RubyFileOps.RubyStatOps.TryCreate(self.Context, Protocols.CastToPath(toPath, path).ConvertToString(), out fsi)) { return(RubyFileOps.RubyStatOps.NullableSize(fsi)); } else { return(null); } }
public static bool IsZeroLength(ConversionStorage <MutableString> /*!*/ toPath, RubyModule /*!*/ self, object path) { string strPath = self.Context.DecodePath(Protocols.CastToPath(toPath, path)); // NUL/nul is a special-cased filename on Windows if (strPath.ToUpperInvariant() == "NUL") { return(RubyFileOps.RubyStatOps.IsZeroLength(RubyFileOps.RubyStatOps.Create(self.Context, strPath))); } if (self.Context.Platform.DirectoryExists(strPath) || !self.Context.Platform.FileExists(strPath)) { return(false); } return(RubyFileOps.RubyStatOps.IsZeroLength(RubyFileOps.RubyStatOps.Create(self.Context, strPath))); }
public static MutableString /*!*/ Read( ConversionStorage <IDictionary <object, object> > /*!*/ toHash, ConversionStorage <int> /*!*/ fixnumCast, ConversionStorage <MutableString> /*!*/ toPath, RubyClass /*!*/ self, object path, [Optional] object optionsOrLength, [Optional] object optionsOrOffset, [DefaultParameterValue(null), DefaultProtocol] IDictionary <object, object> options) { TryConvertToOptions(toHash, ref options, ref optionsOrLength, ref optionsOrOffset); var site = fixnumCast.GetSite(ConvertToFixnumAction.Make(fixnumCast.Context)); int length = (optionsOrLength != Missing.Value && optionsOrLength != null) ? site.Target(site, optionsOrLength) : 0; int offset = (optionsOrOffset != Missing.Value && optionsOrOffset != null) ? site.Target(site, optionsOrOffset) : 0; if (offset < 0) { throw RubyExceptions.CreateEINVAL(); } if (length < 0) { throw RubyExceptions.CreateArgumentError("negative length {0} given", length); } using (RubyIO io = new RubyFile(self.Context, Protocols.CastToPath(toPath, path), IOMode.ReadOnly)) { if (offset > 0) { io.Seek(offset, SeekOrigin.Begin); } if (optionsOrLength != Missing.Value && optionsOrLength != null) { return(Read(io, length, null)); } else { return(Read(io)); } } }
public static object ForEach(ConversionStorage <MutableString> /*!*/ toPath, BlockParam block, RubyClass /*!*/ self, object dirname) { return(new RubyDir(self, Protocols.CastToPath(toPath, dirname)).EnumerateEntries(self.Context, block, null)); }
public static RubyArray /*!*/ GetEntries(ConversionStorage <MutableString> /*!*/ toPath, RubyClass /*!*/ self, object dirname) { return(new RubyDir(self, Protocols.CastToPath(toPath, dirname)).GetEntries(self.Context)); }
public static bool Exists(ConversionStorage <MutableString> /*!*/ toPath, RubyModule /*!*/ self, object path) { return(FileTest.DirectoryExists(self.Context, Protocols.CastToPath(toPath, path))); }
public static bool IsFile(ConversionStorage <MutableString> /*!*/ toPath, RubyModule /*!*/ self, object path) { return(RubyFileOps.FileExists(self.Context, Protocols.CastToPath(toPath, path))); }
public static bool IsUserOwned(ConversionStorage <MutableString> /*!*/ toPath, RubyModule /*!*/ self, object path) { return(RubyFileOps.RubyStatOps.IsUserOwned(RubyFileOps.RubyStatOps.Create(self.Context, Protocols.CastToPath(toPath, path)))); }
public static bool AreIdentical(ConversionStorage <MutableString> /*!*/ toPath, RubyModule /*!*/ self, object path1, object path2) { FileSystemInfo info1, info2; return(RubyFileOps.RubyStatOps.TryCreate(self.Context, self.Context.DecodePath(Protocols.CastToPath(toPath, path1)), out info1) && RubyFileOps.RubyStatOps.TryCreate(self.Context, self.Context.DecodePath(Protocols.CastToPath(toPath, path2)), out info2) && RubyFileOps.RubyStatOps.AreIdentical(self.Context, info1, info2)); }
public static bool IsExecutable(ConversionStorage <MutableString> /*!*/ toPath, RubyModule /*!*/ self, object path) { return(RunIfFileExists(self.Context, Protocols.CastToPath(toPath, path), (FileSystemInfo fsi) => RubyFileOps.RubyStatOps.IsExecutable(fsi))); }
public static RubyDir /*!*/ Open(ConversionStorage <MutableString> /*!*/ toPath, RubyClass /*!*/ self, object dirname) { return(new RubyDir(self, Protocols.CastToPath(toPath, dirname))); }
public static RubyArray /*!*/ GetEntries(ConversionStorage <MutableString> /*!*/ toPath, RubyClass /*!*/ self, object dirname, [Optional] IDictionary <object, object> options) { // TODO: options[:encoding] return(new RubyDir(self, Protocols.CastToPath(toPath, dirname)).GetEntries(self.Context)); }
public static object ChangeDirectory(ConversionStorage <MutableString> /*!*/ toPath, BlockParam block, RubyClass /*!*/ self, object dir) { var d = Protocols.CastToPath(toPath, dir); return(ChangeDirectory(self.Context.Platform, self.Context.DecodePath(d), d, block)); }
public static bool Exists(ConversionStorage <MutableString> /*!*/ toPath, RubyModule /*!*/ self, object path) { var p = Protocols.CastToPath(toPath, path); return(RubyFileOps.FileExists(self.Context, p) || RubyFileOps.DirectoryExists(self.Context, p)); }