Search in sources :

Example 1 with DeleteVolume

use of com.zimbra.cs.redolog.op.DeleteVolume in project zm-mailbox by Zimbra.

the class VolumeManager method delete.

/**
     * Remove the volume from the system.  Files on the volume being deleted are not removed.
     *
     * @return true if actual deletion occurred
     */
public boolean delete(short id, boolean noRedo) throws ServiceException {
    DeleteVolume redoRecorder = null;
    if (!noRedo) {
        redoRecorder = new DeleteVolume(id);
        redoRecorder.start(System.currentTimeMillis());
    }
    // Don't allow deleting the current message/index volume.
    synchronized (this) {
        if (currentMessageVolume != null && id == currentMessageVolume.getId()) {
            throw VolumeServiceException.CANNOT_DELETE_CURRVOL(id, "message");
        }
        if (currentSecondaryMessageVolume != null && id == currentSecondaryMessageVolume.getId()) {
            throw VolumeServiceException.CANNOT_DELETE_CURRVOL(id, "secondary message");
        }
        if (currentIndexVolume != null && id == currentIndexVolume.getId()) {
            throw VolumeServiceException.CANNOT_DELETE_CURRVOL(id, "index");
        }
        Volume vol = getVolume(id);
        if (vol.getType() == Volume.TYPE_MESSAGE || vol.getType() == Volume.TYPE_MESSAGE_SECONDARY) {
            File path = new File(vol.getRootPath());
            String[] files = path.list();
            if (files != null && files.length > 0) {
                //have to check DB to see if any of these files are referenced by mail_item; no FK anymore
                DbConnection conn = DbPool.getConnection();
                try {
                    if (DbVolume.isVolumeReferenced(conn, id)) {
                        ZimbraLog.store.warn("volume %d referenced by mail_item cannot be deleted", id);
                        throw VolumeServiceException.CANNOT_DELETE_VOLUME_IN_USE(id, null);
                    }
                } finally {
                    conn.closeQuietly();
                }
            }
        }
    }
    boolean success = false;
    DbConnection conn = DbPool.getConnection();
    try {
        boolean deleted = DbVolume.delete(conn, id);
        if (!noRedo) {
            redoRecorder.log();
        }
        synchronized (this) {
            id2volume.remove(id);
            updateSweptDirectories();
        }
        success = true;
        return deleted;
    } finally {
        endTransaction(success, conn, redoRecorder);
    }
}
Also used : DeleteVolume(com.zimbra.cs.redolog.op.DeleteVolume) ModifyVolume(com.zimbra.cs.redolog.op.ModifyVolume) DbVolume(com.zimbra.cs.db.DbVolume) CreateVolume(com.zimbra.cs.redolog.op.CreateVolume) SetCurrentVolume(com.zimbra.cs.redolog.op.SetCurrentVolume) DeleteVolume(com.zimbra.cs.redolog.op.DeleteVolume) File(java.io.File) DbConnection(com.zimbra.cs.db.DbPool.DbConnection)

Aggregations

DbConnection (com.zimbra.cs.db.DbPool.DbConnection)1 DbVolume (com.zimbra.cs.db.DbVolume)1 CreateVolume (com.zimbra.cs.redolog.op.CreateVolume)1 DeleteVolume (com.zimbra.cs.redolog.op.DeleteVolume)1 ModifyVolume (com.zimbra.cs.redolog.op.ModifyVolume)1 SetCurrentVolume (com.zimbra.cs.redolog.op.SetCurrentVolume)1 File (java.io.File)1