コード例 #1
0
ファイル: File.cs プロジェクト: mdae/MonoRT
        public static void Delete(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (path.Trim().Length == 0 || path.IndexOfAny(Path.InvalidPathChars) >= 0)
            {
                throw new ArgumentException("path");
            }
            if (Directory.Exists(path))
            {
                throw new UnauthorizedAccessException(Locale.GetText("{0} is a directory", path));
            }

            string DirName = Path.GetDirectoryName(path);

            if (DirName != String.Empty && !Directory.Exists(DirName))
            {
                throw new DirectoryNotFoundException(Locale.GetText("Could not find a part of the path \"{0}\".", path));
            }

            MonoIOError error;

            if (!MonoIO.DeleteFile(path, out error))
            {
                if (error != MonoIOError.ERROR_FILE_NOT_FOUND)
                {
                    throw MonoIO.GetException(path, error);
                }
            }
        }
コード例 #2
0
ファイル: File.cs プロジェクト: yuyixiaoxiang/mono
        public static void Delete(string path)
        {
            Path.Validate(path);
            if (Directory.Exists(path))
            {
                throw new UnauthorizedAccessException(Locale.GetText("{0} is a directory", path));
            }

            string DirName = Path.GetDirectoryName(path);

            if (DirName != String.Empty && !Directory.Exists(DirName))
            {
                throw new DirectoryNotFoundException(Locale.GetText("Could not find a part of the path \"{0}\".", path));
            }

            SecurityManager.EnsureElevatedPermissions();              // this is a no-op outside moonlight

            MonoIOError error;

            if (!MonoIO.DeleteFile(path, out error))
            {
                if (error != MonoIOError.ERROR_FILE_NOT_FOUND)
                {
                    throw MonoIO.GetException(path, error);
                }
            }
        }
コード例 #3
0
ファイル: Directory.cs プロジェクト: Tsalex71/mono-1
        public static void Delete(string path)
        {
            Path.Validate(path);

            if (Environment.IsRunningOnWindows && path == ":")
            {
                throw new NotSupportedException("Only ':' In path");
            }

            SecurityManager.EnsureElevatedPermissions();              // this is a no-op outside moonlight

            MonoIOError error;
            bool        success;

            if (MonoIO.ExistsSymlink(path, out error))
            {
                /* RemoveDirectory maps to rmdir()
                 * which fails on symlinks (ENOTDIR)
                 */
                success = MonoIO.DeleteFile(path, out error);
            }
            else
            {
                success = MonoIO.RemoveDirectory(path, out error);
            }

            if (!success)
            {
                /*
                 * FIXME:
                 * In io-layer/io.c rmdir returns error_file_not_found if directory does not exist.
                 * So maybe this could be handled somewhere else?
                 */
                if (error == MonoIOError.ERROR_FILE_NOT_FOUND)
                {
                    if (File.Exists(path))
                    {
                        throw new IOException("Directory does not exist, but a file of the same name exists.");
                    }
                    else
                    {
                        throw new DirectoryNotFoundException("Directory does not exist.");
                    }
                }
                else
                {
                    throw MonoIO.GetException(path, error);
                }
            }
        }
コード例 #4
0
        /// <summary>Permanently deletes a file.</summary>
        /// <exception cref="T:System.IO.IOException">The target file is open or memory-mapped on a computer running Microsoft Windows NT. </exception>
        /// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission. </exception>
        /// <exception cref="T:System.UnauthorizedAccessException">The path is a directory. </exception>
        /// <filterpriority>1</filterpriority>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        /// </PermissionSet>
        public override void Delete()
        {
            MonoIOError error;

            if (!MonoIO.Exists(this.FullPath, out error))
            {
                return;
            }
            if (MonoIO.ExistsDirectory(this.FullPath, out error))
            {
                throw new UnauthorizedAccessException("Access to the path \"" + this.FullPath + "\" is denied.");
            }
            if (!MonoIO.DeleteFile(this.FullPath, out error))
            {
                throw MonoIO.GetException(this.OriginalPath, error);
            }
        }
コード例 #5
0
        // file methods

        public override void Delete()
        {
            MonoIOError error;

            if (!MonoIO.Exists(FullPath, out error))
            {
                // a weird MS.NET behaviour
                return;
            }

            if (MonoIO.ExistsDirectory(FullPath, out error))
            {
                throw new UnauthorizedAccessException("Access to the path \"" + FullPath + "\" is denied.");
            }
            if (!MonoIO.DeleteFile(FullPath, out error))
            {
                throw MonoIO.GetException(OriginalPath, error);
            }
        }
コード例 #6
0
        // file methods

        public override void Delete()
        {
            MonoIOError error;

            SecurityManager.EnsureElevatedPermissions();              // this is a no-op outside moonlight

            if (!MonoIO.Exists(FullPath, out error))
            {
                // a weird MS.NET behaviour
                return;
            }

            if (MonoIO.ExistsDirectory(FullPath, out error))
            {
                throw new UnauthorizedAccessException("Access to the path \"" + FullPath + "\" is denied.");
            }
            if (!MonoIO.DeleteFile(FullPath, out error))
            {
                throw MonoIO.GetException(OriginalPath, error);
            }
        }
コード例 #7
0
ファイル: fileinfo.cs プロジェクト: zhufengGNSS/mono
        public override void Delete()
        {
#if FEATURE_MONO_CAS
#if FEATURE_CORECLR
            FileSecurityState state = new FileSecurityState(FileSecurityStateAccess.Write, DisplayPath, FullPath);
            state.EnsureState();
#else
            // For security check, path should be resolved to an absolute path.
            FileIOPermission.QuickDemand(FileIOPermissionAccess.Write, FullPath, false, false);
#endif
#endif

#if MONO
            MonoIOError error;

            if (MonoIO.ExistsDirectory(FullPath, out error))
            {
                __Error.WinIOError(Win32Native.ERROR_ACCESS_DENIED, DisplayPath);
            }

            if (!MonoIO.DeleteFile(FullPath, out error))
            {
                int hr = (int)error;
#else
            bool r = Win32Native.DeleteFile(FullPath);
            if (!r)
            {
                int hr = Marshal.GetLastWin32Error();
#endif
                if (hr == Win32Native.ERROR_FILE_NOT_FOUND)
                {
                    return;
                }
                else
                {
                    __Error.WinIOError(hr, DisplayPath);
                }
            }
        }
コード例 #8
0
ファイル: Directory.cs プロジェクト: Tsalex71/mono-1
        static void RecursiveDelete(string path)
        {
            MonoIOError error;

            foreach (string dir in GetDirectories(path))
            {
                if (MonoIO.ExistsSymlink(dir, out error))
                {
                    MonoIO.DeleteFile(dir, out error);
                }
                else
                {
                    RecursiveDelete(dir);
                }
            }

            foreach (string file in GetFiles(path))
            {
                File.Delete(file);
            }

            Directory.Delete(path);
        }
コード例 #9
0
        public static void Delete(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (path.Length == 0)
            {
                throw new ArgumentException("Path is empty");
            }

            if (path.IndexOfAny(Path.InvalidPathChars) != -1)
            {
                throw new ArgumentException("Path contains invalid chars");
            }

            if (path.Trim().Length == 0)
            {
                throw new ArgumentException("Only blank characters in path");
            }

            if (path == ":")
            {
                throw new NotSupportedException("Only ':' In path");
            }

            MonoIOError error;
            bool        success;

            if (MonoIO.ExistsSymlink(path, out error))
            {
                /* RemoveDirectory maps to rmdir()
                 * which fails on symlinks (ENOTDIR)
                 */
                success = MonoIO.DeleteFile(path, out error);
            }
            else
            {
                success = MonoIO.RemoveDirectory(path, out error);
            }

            if (!success)
            {
                /*
                 * FIXME:
                 * In io-layer/io.c rmdir returns error_file_not_found if directory does not exists.
                 * So maybe this could be handled somewhere else?
                 */
                if (error == MonoIOError.ERROR_FILE_NOT_FOUND)
                {
                    if (File.Exists(path))
                    {
                        throw new IOException("Directory does not exist, but a file of the same name exist.");
                    }
                    else
                    {
                        throw new DirectoryNotFoundException("Directory does not exist.");
                    }
                }
                else
                {
                    throw MonoIO.GetException(path, error);
                }
            }
        }