示例#1
0
        static void UnixRename(string sourceFile, string destFile)
        {
            if (Stdlib.rename(sourceFile, destFile) != 0)
            {
                switch (Stdlib.GetLastError())
                {
                case Errno.EACCES:
                case Errno.EPERM:
                    throw new UnauthorizedAccessException();

                case Errno.EINVAL:
                    throw new InvalidOperationException();

                case Errno.ENOTDIR:
                    throw new DirectoryNotFoundException();

                case Errno.ENOENT:
                    throw new FileNotFoundException();

                case Errno.ENAMETOOLONG:
                    throw new PathTooLongException();

                default:
                    throw new IOException();
                }
            }
        }
示例#2
0
        static void UnixRename(string sourceFile, string destFile)
        {
            if (Stdlib.rename(sourceFile, destFile) != 0)
            {
                switch (Stdlib.GetLastError())
                {
                case Errno.EACCES:
                case Errno.EPERM:
                    throw new UnauthorizedAccessException();

                case Errno.EINVAL:
                    throw new InvalidOperationException();

                case Errno.ENOTDIR:
                    throw new DirectoryNotFoundException();

                case Errno.ENOENT:
                    throw new FileNotFoundException();

                case Errno.ENAMETOOLONG:
                    throw new PathTooLongException();

                case Errno.EXDEV:
                    throw new IOException(GettextCatalog.GetString("Invalid file move accross filesystem boundaries."));

                default:
                    throw new IOException("Error:" + Stdlib.GetLastError());
                }
            }
        }
        public override Errno OnRenamePath(string oldpath, string newpath)
        {
            Trace.WriteLine($"OnRenamePath {oldpath} to {newpath}");

            int r = Stdlib.rename(oldpath, newpath);

            if (r < 0)
            {
                return(Stdlib.GetLastError());
            }

            return(0);
        }
        /// <inheritdoc />
        public Task <IUnixFileSystemEntry> MoveAsync(
            IUnixDirectoryEntry parent,
            IUnixFileSystemEntry source,
            IUnixDirectoryEntry target,
            string fileName,
            CancellationToken cancellationToken)
        {
            var sourceInfo      = ((UnixFileSystemEntry)source).GenericInfo;
            var targetEntry     = (UnixDirectoryEntry)target;
            var targetInfo      = targetEntry.Info;
            var sourceEntryName = sourceInfo.FullName;
            var targetEntryName = UnixPath.Combine(targetInfo.FullName, fileName);

            if (Stdlib.rename(sourceEntryName, targetEntryName) == -1)
            {
                throw new InvalidOperationException("The entry couldn't be moved.");
            }

            var targetEntryInfo = UnixFileSystemInfo.GetFileSystemEntry(targetEntryName);

            return(Task.FromResult(CreateEntry(targetEntry, targetEntryInfo)));
        }