示例#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);
                }
            }
        }