Пример #1
0
        private void Check(SourceDestFileInfo info)
        {
            if (Locker.IsLocked(info.DestinationFileName))
            {
                throw new FileIsLockedException(info.DestinationFileName);
            }


            // TODO: write normal checking
            if (!File.Exists(info.SourceFileName))
            {
                throw new FileNotFoundException(info.SourceFileName);
            }

            UserFileAccessRightsChecker sourceChecker = new UserFileAccessRightsChecker(info.SourceFileName);

            if (!sourceChecker.CanRead())
            {
                throw new AccessDeniedException(info.SourceFileName);
            }
            if (!sourceChecker.CanDelete())
            {
                throw new AccessDeniedException(info.SourceFileName);
            }

            UserFileAccessRightsChecker destDirChecker = new UserFileAccessRightsChecker(Path.GetDirectoryName(info.DestinationFileName));

            if (!destDirChecker.CanCreateFiles())
            {
                throw new AccessDeniedException(info.DestinationFileName);
            }


            if (File.Exists(info.DestinationFileName))
            {
                /*if (_overwrite)
                 * {
                 * UserFileAccessRightsChecker destFileChecker =  new UserFileAccessRightsChecker(info.DestinationFileName );
                 * if (!destFileChecker.CanDelete())
                 *  throw new AccessDeniedException(info.DestinationFileName );
                 * }
                 * else
                 * {*/
                throw new FileAlreadyExistException(info.DestinationFileName);
                //}
            }
        }
Пример #2
0
        private void Check(SourceDestFileInfo info, bool overwrite)
        {
            if (Locker.IsLocked(info.DestinationFileName))
            {
                throw new FileIsLockedException(info.DestinationFileName);
            }

            // TODO: write normal checking
            if (!File.Exists(info.SourceFileName))
            {
                throw new FileNotFoundException(info.SourceFileName);
            }
            UserFileAccessRightsChecker sourceChecker = new UserFileAccessRightsChecker(info.SourceFileName);

            if (!sourceChecker.CanRead())
            {
                throw new AccessDeniedException(info.SourceFileName);
            }
            UserFileAccessRightsChecker destChecker =
                new UserFileAccessRightsChecker(Path.GetDirectoryName(info.DestinationFileName));

            if (!destChecker.CanCreateFiles())
            {
                throw new AccessDeniedException(info.DestinationFileName);
            }

            if (File.Exists(info.DestinationFileName))
            {
                if (overwrite)
                {
                    UserFileAccessRightsChecker destFileChecker = new UserFileAccessRightsChecker(info.DestinationFileName);
                    if (!destFileChecker.CanModify())
                    {
                        throw new AccessDeniedException(info.DestinationFileName);
                    }
                }
                else
                {
                    throw new FileAlreadyExistException(info.DestinationFileName);
                }
            }
        }
Пример #3
0
        private static void Check(SourceFileInfo info)
        {
            // TODO: write normal checking
            if (File.Exists(info.SourceFileName) || Directory.Exists(info.SourceFileName))
            {
                throw new FileAlreadyExistException(info.SourceFileName);
            }

            string rootDirectoryPath = "";

            if (info.SourceFileName.Contains(Path.DirectorySeparatorChar.ToString()))
            {
                rootDirectoryPath = info.SourceFileName.Substring(0, info.SourceFileName.LastIndexOf(Path.DirectorySeparatorChar));
            }

            UserFileAccessRightsChecker directoryChecker = new UserFileAccessRightsChecker(rootDirectoryPath);

            if (!directoryChecker.CanCreateDirectories())
            {
                throw new AccessDeniedException(info.SourceFileName);
            }
        }