Пример #1
0
        /// <summary>
        ///  Rename dir/file
        /// </summary>
        private bool __rename(string newName)
        {
            if ((newName = checkInvalidChars(newName)) == null)
            {
                SqlFsErrCode.CurrentError = FsErr.InvalidChars;
                return(false);
            }

            if (this.ID.Equals(SqlFsConst.ROOTDIRID))        // can't rename root
            {
                SqlFsErrCode.CurrentError = FsErr.CannotRenameRoot;
                return(false);
            }

            SqlDir parentDir = this.Parent;

            if (parentDir == null)
            {
                SqlFsErrCode.CurrentError = FsErr.NoParent;
                return(false);
            }

            if (parentDir.isAlreadyExist(newName))        // already exists or not ?
            {
                SqlFsErrCode.CurrentError = FsErr.NameAlreadyExists;
                return(false);
            }

            setField(SqlFs.FSBLOCK.fsName, newName);

            return(true);
        }
Пример #2
0
        /// <summary>
        ///  Move itself to a destination dir
        /// </summary>
        private bool __move(SqlDir destDir)
        {
            do
            {
                if (this.ID.Equals(SqlFsConst.ROOTDIRID))           // can't move root
                {
                    SqlFsErrCode.CurrentError = FsErr.CannotMoveRoot;
                    break;
                }

                if (this.ID.Equals(destDir.ID))           // can't move to itself
                {
                    SqlFsErrCode.CurrentError = FsErr.CannotMoveToSelf;
                    break;
                }

                if (this.Dir && destDir.isAncestor((SqlDir)this))           // if it is a DIR, can't move to its subdir
                {
                    SqlFsErrCode.CurrentError = FsErr.CannotMoveToSubdir;
                    break;
                }

                if (destDir.isAlreadyExist(this.Name))           // can't move if there is one with the same name
                {
                    SqlFsErrCode.CurrentError = FsErr.NameAlreadyExists;
                    break;
                }

                // unlink itself from parent
                SqlDir parent = this.Parent;
                if (parent == null)
                {
                    SqlFsErrCode.CurrentError = FsErr.NoParent;
                    break;
                }

                if (!parent.updateChildList(SqlFsConst.FSOP.DEL, this.ID, FsID.toFsID(0)))
                {
                    break;
                }

                // update parent ID
                if (!setField(SqlFs.FSBLOCK.fsParent, destDir.ID))
                {
                    break;
                }

                // add itself to dest dir
                if (!destDir.updateChildList(SqlFsConst.FSOP.ADD, this.ID, FsID.toFsID(0)))
                {
                    break;
                }

                return(true);
            } while (false);

            return(false);
        }