Ejemplo n.º 1
0
        /// <summary>
        /// Returns the attributes of the given file, taking into account whether
        /// the walk is following sym links is not. The {@code canUseCached}
        /// argument determines whether this method can use cached attributes.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private java.nio.file.attribute.BasicFileAttributes getAttributes(Path file, boolean canUseCached) throws java.io.IOException
        private BasicFileAttributes GetAttributes(Path file, bool canUseCached)
        {
            // if attributes are cached then use them if possible
            if (canUseCached && (file is BasicFileAttributesHolder) && (System.SecurityManager == null))
            {
                BasicFileAttributes cached = ((BasicFileAttributesHolder)file).get();
                if (cached != null && (!FollowLinks || !cached.SymbolicLink))
                {
                    return(cached);
                }
            }

            // attempt to get attributes of file. If fails and we are following
            // links then a link target might not exist so get attributes of link
            BasicFileAttributes attrs;

            try
            {
                attrs = Files.ReadAttributes(file, typeof(BasicFileAttributes), LinkOptions);
            }
            catch (IOException ioe)
            {
                if (!FollowLinks)
                {
                    throw ioe;
                }

                // attempt to get attrmptes without following links
                attrs = Files.ReadAttributes(file, typeof(BasicFileAttributes), LinkOption.NOFOLLOW_LINKS);
            }
            return(attrs);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Simple copy for use when source and target are associated with different
        /// providers
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static void copyToForeignTarget(Path source, Path target, CopyOption... options) throws java.io.IOException
        internal static void CopyToForeignTarget(Path source, Path target, params CopyOption[] options)
        {
            CopyOptions opts = CopyOptions.Parse(options);

            LinkOption[] linkOptions = (opts.FollowLinks) ? new LinkOption[0] : new LinkOption[] { LinkOption.NOFOLLOW_LINKS };

            // attributes of source file
            BasicFileAttributes attrs = Files.ReadAttributes(source, typeof(BasicFileAttributes), linkOptions);

            if (attrs.SymbolicLink)
            {
                throw new IOException("Copying of symbolic links not supported");
            }

            // delete target if it exists and REPLACE_EXISTING is specified
            if (opts.ReplaceExisting)
            {
                Files.DeleteIfExists(target);
            }
            else if (Files.exists(target))
            {
                throw new FileAlreadyExistsException(target.ToString());
            }

            // create directory or copy file
            if (attrs.Directory)
            {
                Files.createDirectory(target);
            }
            else
            {
                using (InputStream @in = Files.newInputStream(source))
                {
                    Files.Copy(@in, target);
                }
            }

            // copy basic attributes to target
            if (opts.CopyAttributes)
            {
                BasicFileAttributeView view = Files.getFileAttributeView(target, typeof(BasicFileAttributeView));
                try
                {
                    view.SetTimes(attrs.LastModifiedTime(), attrs.LastAccessTime(), attrs.CreationTime());
                }
                catch (Throwable x)
                {
                    // rollback
                    try
                    {
                        Files.Delete(target);
                    }
                    catch (Throwable suppressed)
                    {
                        x.AddSuppressed(suppressed);
                    }
                    throw x;
                }
            }
        }
Ejemplo n.º 3
0
 internal Event(EventType type, Path file, BasicFileAttributes attrs, IOException ioe)
 {
     this.Type_Renamed = type;
     this.File_Renamed = file;
     this.Attrs        = attrs;
     this.Ioe          = ioe;
 }
Ejemplo n.º 4
0
            public override FileVisitResult visitFile(Path path, BasicFileAttributes attrs)
            {
                File file         = path.toFile();
                Path name         = path.getName(path.NameCount - 3);
                bool isLuceneFile = (path.NameCount >= 3 && name.ToString().StartsWith("lucene-", StringComparison.Ordinal)) || (path.NameCount >= 4 && path.getName(path.NameCount - 4).ToString().Equals("lucene"));

                if (!FailureStorage.DEFAULT_FAILURE_FILE_NAME.Equals(file.Name))
                {
                    (isLuceneFile ? _luceneTotal : _pageCacheTotal).add(file.length());
                }
                return(FileVisitResult.CONTINUE);
            }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public java.nio.file.FileVisitResult visitFile(java.nio.file.Path file, java.nio.file.attribute.BasicFileAttributes attrs) throws java.io.IOException
            public override FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
            {
                DeleteFile(file);
                return(FileVisitResult.CONTINUE);
            }
Ejemplo n.º 6
0
        /// <summary>
        /// Invoked for a file in a directory.
        ///
        /// <para> Unless overridden, this method returns {@link FileVisitResult#CONTINUE
        /// CONTINUE}.
        /// </para>
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public FileVisitResult visitFile(T file, java.nio.file.attribute.BasicFileAttributes attrs) throws java.io.IOException
        public override FileVisitResult VisitFile(T file, BasicFileAttributes attrs)
        {
            Objects.RequireNonNull(file);
            Objects.RequireNonNull(attrs);
            return(FileVisitResult.CONTINUE);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Invoked for a directory before entries in the directory are visited.
        ///
        /// <para> Unless overridden, this method returns {@link FileVisitResult#CONTINUE
        /// CONTINUE}.
        /// </para>
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public FileVisitResult preVisitDirectory(T dir, java.nio.file.attribute.BasicFileAttributes attrs) throws java.io.IOException
        public override FileVisitResult PreVisitDirectory(T dir, BasicFileAttributes attrs)
        {
            Objects.RequireNonNull(dir);
            Objects.RequireNonNull(attrs);
            return(FileVisitResult.CONTINUE);
        }
Ejemplo n.º 8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public java.nio.file.FileVisitResult visitFile(java.nio.file.Path file, java.nio.file.attribute.BasicFileAttributes attrs) throws java.io.IOException
            public override FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
            {
                return(_predicate(file) ? _wrapped.visitFile(file, attrs) : FileVisitResult.CONTINUE);
            }
Ejemplo n.º 9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public java.nio.file.FileVisitResult preVisitDirectory(java.nio.file.Path dir, java.nio.file.attribute.BasicFileAttributes attrs) throws java.io.IOException
            public override FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
            {
                return(_predicate(dir) ? _wrapped.preVisitDirectory(dir, attrs) : FileVisitResult.SKIP_SUBTREE);
            }
Ejemplo n.º 10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public java.nio.file.FileVisitResult visitFile(T t, java.nio.file.attribute.BasicFileAttributes attrs) throws java.io.IOException
            public override FileVisitResult VisitFile(T t, BasicFileAttributes attrs)
            {
                return(Wrapped.visitFile(t, attrs));
            }
Ejemplo n.º 11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public java.nio.file.FileVisitResult preVisitDirectory(T t, java.nio.file.attribute.BasicFileAttributes attrs) throws java.io.IOException
            public override FileVisitResult PreVisitDirectory(T t, BasicFileAttributes attrs)
            {
                return(Wrapped.preVisitDirectory(t, attrs));
            }
Ejemplo n.º 12
0
 public override FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
 {
     return(FileVisitResult.CONTINUE);
 }
Ejemplo n.º 13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public java.nio.file.FileVisitResult visitFile(java.nio.file.Path file, java.nio.file.attribute.BasicFileAttributes attrs) throws java.io.IOException
            public override FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
            {
                _operation.accept(file);
                return(base.visitFile(file, attrs));
            }
Ejemplo n.º 14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public java.nio.file.FileVisitResult preVisitDirectory(java.nio.file.Path dir, java.nio.file.attribute.BasicFileAttributes attrs) throws java.io.IOException
            public override FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
            {
                _operation.accept(dir);
                return(base.preVisitDirectory(dir, attrs));
            }
Ejemplo n.º 15
0
 internal Event(EventType type, Path file, BasicFileAttributes attrs) : this(type, file, attrs, null)
 {
 }