Beispiel #1
0
        public static void FileSystemEventArgs_ctor_DirectoryIsRelativePath_Unix(string directory, string name)
        {
            FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);

            var expectedDirectory = PathInternal.EnsureTrailingSeparator(Path.Combine(Directory.GetCurrentDirectory(), directory));

            Assert.Equal(Path.Combine(expectedDirectory, name), args.FullPath);
        }
        public static void FileSystemEventArgs_ctor_When_EmptyFileName_Then_FullPathReturnsTheDirectoryFullPath_WithTrailingSeparator(string directory, string name)
        {
            FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);

            directory = PathInternal.EnsureTrailingSeparator(directory);

            Assert.Equal(PathInternal.EnsureTrailingSeparator(Directory.GetCurrentDirectory()) + directory, args.FullPath);
        }
Beispiel #3
0
        public static void RenamedEventArgs_ctor_OldFullPath_DirectoryIsRelativePath_Windows(string directory, string name, string oldName)
        {
            RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);

            var expectedDirectory = PathInternal.EnsureTrailingSeparator(Path.Combine(Directory.GetCurrentDirectory(), directory));

            Assert.Equal(Path.Combine(expectedDirectory, oldName), args.OldFullPath);
        }
Beispiel #4
0
        public static void Move(string sourceDirName, string destDirName)
        {
            if (sourceDirName == null)
            {
                throw new ArgumentNullException(nameof(sourceDirName));
            }
            if (sourceDirName.Length == 0)
            {
                throw new ArgumentException(SR.Argument_EmptyFileName, nameof(sourceDirName));
            }

            if (destDirName == null)
            {
                throw new ArgumentNullException(nameof(destDirName));
            }
            if (destDirName.Length == 0)
            {
                throw new ArgumentException(SR.Argument_EmptyFileName, nameof(destDirName));
            }

            string fullsourceDirName = Path.GetFullPath(sourceDirName);
            string sourcePath        = PathInternal.EnsureTrailingSeparator(fullsourceDirName);

            string fulldestDirName = Path.GetFullPath(destDirName);
            string destPath        = PathInternal.EnsureTrailingSeparator(fulldestDirName);

            StringComparison pathComparison = PathInternal.StringComparison;

            if (string.Equals(sourcePath, destPath, pathComparison))
            {
                throw new IOException(SR.IO_SourceDestMustBeDifferent);
            }

            string sourceRoot      = Path.GetPathRoot(sourcePath);
            string destinationRoot = Path.GetPathRoot(destPath);

            if (!string.Equals(sourceRoot, destinationRoot, pathComparison))
            {
                throw new IOException(SR.IO_SourceDestMustHaveSameRoot);
            }

            // Windows will throw if the source file/directory doesn't exist, we preemptively check
            // to make sure our cross platform behavior matches NetFX behavior.
            if (!FileSystem.DirectoryExists(fullsourceDirName) && !FileSystem.FileExists(fullsourceDirName))
            {
                throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, fullsourceDirName));
            }

            if (FileSystem.DirectoryExists(fulldestDirName))
            {
                throw new IOException(SR.Format(SR.IO_AlreadyExists_Name, fulldestDirName));
            }

            FileSystem.MoveDirectory(fullsourceDirName, fulldestDirName);
        }
Beispiel #5
0
        /// <devdoc>
        ///    Initializes a new instance of the <see cref='System.IO.RenamedEventArgs'/> class.
        /// </devdoc>
        public RenamedEventArgs(WatcherChangeTypes changeType, string directory, string?name, string?oldName)
            : base(changeType, directory, name)
        {
            _oldName     = oldName;
            _oldFullPath = Path.Join(Path.GetFullPath(directory), oldName);

            if (string.IsNullOrWhiteSpace(oldName))
            {
                _oldFullPath = PathInternal.EnsureTrailingSeparator(_oldFullPath);
            }
        }
Beispiel #6
0
        /// <devdoc>
        /// Initializes a new instance of the <see cref='System.IO.FileSystemEventArgs'/> class.
        /// </devdoc>
        public FileSystemEventArgs(WatcherChangeTypes changeType, string directory, string?name)
        {
            _changeType = changeType;
            _name       = name;
            _fullPath   = Path.Join(Path.GetFullPath(directory), name);

            if (string.IsNullOrWhiteSpace(name))
            {
                _fullPath = PathInternal.EnsureTrailingSeparator(_fullPath);
            }
        }
Beispiel #7
0
        public void MoveTo(string destDirName)
        {
            if (destDirName == null)
            {
                throw new ArgumentNullException(nameof(destDirName));
            }
            if (destDirName.Length == 0)
            {
                throw new ArgumentException(SR.Argument_EmptyFileName, nameof(destDirName));
            }

            string destination = Path.GetFullPath(destDirName);

            string destinationWithSeparator = PathInternal.EnsureTrailingSeparator(destination);
            string sourceWithSeparator      = PathInternal.EnsureTrailingSeparator(FullPath);

            if (string.Equals(sourceWithSeparator, destinationWithSeparator, PathInternal.StringComparison))
            {
                throw new IOException(SR.IO_SourceDestMustBeDifferent);
            }

            string sourceRoot      = Path.GetPathRoot(sourceWithSeparator);
            string destinationRoot = Path.GetPathRoot(destinationWithSeparator);

            if (!string.Equals(sourceRoot, destinationRoot, PathInternal.StringComparison))
            {
                throw new IOException(SR.IO_SourceDestMustHaveSameRoot);
            }

            // Windows will throw if the source file/directory doesn't exist, we preemptively check
            // to make sure our cross platform behavior matches NetFX behavior.
            if (!Exists && !FileSystem.FileExists(FullPath))
            {
                throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, FullPath));
            }

            if (FileSystem.DirectoryExists(destination))
            {
                throw new IOException(SR.Format(SR.IO_AlreadyExists_Name, destinationWithSeparator));
            }

            FileSystem.MoveDirectory(FullPath, destination);

            Init(originalPath: destDirName,
                 fullPath: destinationWithSeparator,
                 fileName: null,
                 isNormalized: true);

            // Flush any cached information about the directory.
            Invalidate();
        }
Beispiel #8
0
        /// <devdoc>
        ///    Initializes a new instance of the <see cref='System.IO.RenamedEventArgs'/> class.
        /// </devdoc>
        public RenamedEventArgs(WatcherChangeTypes changeType, string directory, string?name, string?oldName)
            : base(changeType, directory, name)
        {
            _oldName = oldName;

            if (directory.Length == 0) // empty directory means current working dir
            {
                directory = ".";
            }

            string fullDirectoryPath = Path.GetFullPath(directory);

            _oldFullPath = string.IsNullOrEmpty(oldName) ? PathInternal.EnsureTrailingSeparator(fullDirectoryPath) : Path.Join(fullDirectoryPath, oldName);
        }
Beispiel #9
0
        /// <devdoc>
        /// Initializes a new instance of the <see cref='System.IO.FileSystemEventArgs'/> class.
        /// </devdoc>
        public FileSystemEventArgs(WatcherChangeTypes changeType, string directory, string?name)
        {
            ArgumentNullException.ThrowIfNull(directory);

            _changeType = changeType;
            _name       = name;

            if (directory.Length == 0) // empty directory means current working dir
            {
                directory = ".";
            }

            string fullDirectoryPath = Path.GetFullPath(directory);

            _fullPath = string.IsNullOrEmpty(name) ? PathInternal.EnsureTrailingSeparator(fullDirectoryPath) : Path.Join(fullDirectoryPath, name);
        }