Пример #1
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);
        }
Пример #2
0
        /// <summary>
        ///  delete all dirs and files recursively
        /// </summary>
        private bool __delete()
        {
            bool isOK = false;

            do
            {
                // delete itself from parent
                if (!this.ID.Equals(SqlFsConst.ROOTDIRID))           // root has no 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;
                    }
                }

                // delete underlying subdirs and files
                List <SqlFsNode> childList = this.ChildList;

                if (childList != null)
                {
                    // delete children one by one
                    foreach (SqlFsNode fsNode in childList)
                    {
                        fsNode.delete();
                    }
                }

                // delete itself
                if (this.ID.Equals(SqlFsConst.ROOTDIRID))
                {
                    // for root, just clear all children
                    this.setField(SqlFs.FSBLOCK.fsChild, null);
                }
                else
                {
                    if (!SqlFs.deleteEntryByID(db, SqlFs.DBNAMES.FsBlock.ToString(), SqlFs.FSBLOCK.fsID.ToString(), this.ID))
                    {
                        SqlFsErrCode.CurrentError = FsErr.CannotDeleteFsEntry;
                        break;
                    }
                }

                isOK = true;
            } while (false);

            return(isOK);
        }
Пример #3
0
        private bool __delete()
        {
            bool isOK = false;

            do
            {
                // delete 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;
                }

                // delete entry in data block table
                FsID dataBlockID = this.getDataBlockID();
                if (dataBlockID.compare(SqlFsConst.INVALIDID) <= 0)
                {
                    //SqlFsLog.debug("+++ dataBlockID = " + dataBlockID.getVal());
                    SqlFsErrCode.CurrentError = FsErr.DataBlockIDNotValid;
                    break;
                }

                if (!SqlFs.deleteEntryByID(db, IFileData.DTABLENAME, IFileData.IDCOL, dataBlockID))
                {
                    SqlFsErrCode.CurrentError = FsErr.CannotDeleteDataBlockEntry;
                    break;
                }

                // delete its own entry
                if (!SqlFs.deleteEntryByID(db, SqlFs.DBNAMES.FsBlock.ToString(), SqlFs.FSBLOCK.fsID.ToString(), this.ID))
                {
                    SqlFsErrCode.CurrentError = FsErr.CannotDeleteFsEntry;
                    break;
                }

                isOK = true;
            } while (false);

            return(isOK);
        }