Exemple #1
0
        public static MutableString /*!*/ ExpandPath(
            RubyClass /*!*/ self,
            [DefaultProtocol, NotNull] MutableString /*!*/ path,
            [DefaultProtocol, Optional] MutableString basePath)
        {
            var context = self.Context;

            string result = RubyUtils.ExpandPath(
                context.Platform,
                context.DecodePath(path),
                basePath == null ? null : context.DecodePath(basePath)
                );

            return(self.Context.EncodePath(result));
        }
        private string[] GetPaths(string input)
        {
            string[] paths = StringUtils.Split(input, new char[] { Path.PathSeparator }, Int32.MaxValue, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < paths.Length; i++)
            {
                string path = paths[i];

                if (!RubyUtils.IsRelativeToCurrentDirectory(path))
                {
                    paths[i] = RubyUtils.ExpandPath(Platform, path, Platform.CurrentDirectory, true);
                }
            }

            return(paths);
        }
Exemple #3
0
        public static int Rename(RubyClass /*!*/ self,
                                 [DefaultProtocol, NotNull] MutableString /*!*/ oldPath, [DefaultProtocol, NotNull] MutableString /*!*/ newPath)
        {
            if (oldPath.IsEmpty || newPath.IsEmpty)
            {
                throw RubyExceptions.CreateENOENT();
            }

            var context = self.Context;

            string strOldPath = context.DecodePath(oldPath);

            if (!context.Platform.FileExists(strOldPath) && !context.Platform.DirectoryExists(strOldPath))
            {
                throw RubyExceptions.CreateENOENT("No such file or directory - {0}", oldPath);
            }

            string strNewPath = context.DecodePath(newPath);

            if (RubyUtils.ExpandPath(context.Platform, strOldPath) == RubyUtils.ExpandPath(context.Platform, strNewPath))
            {
                return(0);
            }

            if (context.Platform.FileExists(strNewPath))
            {
                Delete(context, strNewPath);
            }

            try {
                context.Platform.MoveFileSystemEntry(strOldPath, strNewPath);
            } catch (IOException e) {
                throw Errno.CreateEACCES(e.Message, e);
            }

            return(0);
        }