Beispiel #1
0
        /// <summary>
        ///   Add an empty dir
        /// </summary>
        ///   <returns> the newly created dir </returns>
        private SqlDir __addDir(string dirName)
        {
            if ((dirName = checkInvalidChars(dirName)) == null)
            {
                SqlFsErrCode.CurrentError = FsErr.InvalidChars;
                return(null);
            }

            if (__isAlreadyExist(dirName))
            {
                SqlFsErrCode.CurrentError = FsErr.NameAlreadyExists;
                return(null);
            }

            FsID newID = SqlDir.addDir(db, dirName, this.ID);

            if (newID.compare(SqlFsConst.INVALIDID) <= 0)
            {
                SqlFsErrCode.CurrentError = FsErr.NoNewIDForNewFsNode;
                return(null);
            }

            if (!updateChildList(SqlFsConst.FSOP.ADD, newID, FsID.toFsID(0)))
            {
                // delete entry just created
                SqlFs.deleteEntryByID(db, SqlFs.DBNAMES.FsBlock.ToString(), SqlFs.FSBLOCK.fsID.ToString(), newID);
                return(null);
            }

            return(SqlDir.getDir(db, fsLocker, newID));
        }
Beispiel #2
0
        /// <summary>
        ///  Add a new entry for file. File must be saved so as to be
        ///  appeared under its parent directory.
        /// </summary>
        private SqlFile __addFile(string fileName)
        {
            if ((fileName = checkInvalidChars(fileName)) == null)
            {
                SqlFsErrCode.CurrentError = FsErr.InvalidChars;
                return(null);
            }

            if (__isAlreadyExist(fileName))
            {
                SqlFsErrCode.CurrentError = FsErr.NameAlreadyExists;
                return(null);
            }

            FsID newID = SqlFile.addFile(db, fileName, this.ID);

            if (newID.compare(SqlFsConst.INVALIDID) <= 0)
            {
                SqlFsErrCode.CurrentError = FsErr.NoNewIDForNewFsNode;
                return(null);
            }

            if (!updateChildList(SqlFsConst.FSOP.ADD, newID, FsID.toFsID(0)))
            {
                // delete entry just created
                SqlFs.deleteEntryByID(db, SqlFs.DBNAMES.FsBlock.ToString(), SqlFs.FSBLOCK.fsID.ToString(), newID);
                return(null);
            }

            SqlFile f = SqlFile.getFile(db, fsLocker, newID);

            f.setDataBlockID(SqlFsConst.NOFILEDATAID);
            return(f);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }