/// <summary> /// Deletes a file or directory. If <paramref name="file"/> is a directory, then its entire content is deleted as well. /// </summary> /// <param name="file"></param> /// <returns></returns> public async Task <FileResult> Delete(SoundboxNode file) { file = GetCleanFile(file); if (file == null) { return(new FileResult(BaseResultStatus.INVALID_PARAMETER)); } if (IsRootDirectory(file)) { return(new FileResult(FileResultStatus.ILLEGAL_FILE_EDIT_DENIED_ROOT)); } try { DatabaseLock.EnterWriteLock(); //save previous watermark for event Guid previousWatermark = GetRootWatermark(); Guid newWatermark = Guid.NewGuid(); //remove from cache file.ParentDirectory.Children.Remove(file); NodesCache.Remove(file.ID); //do not remove the parent from the file: need it for the client event //remove from disk DeleteRecursive(file); //delete from database //TODO async Database.Delete(file); //update cache and database watermarks (this will call Update for parent) SetWatermark(file, newWatermark); //update our clients GetHub().OnFileEvent(new SoundboxFileChangeEvent() { Event = SoundboxFileChangeEvent.Type.DELETED, File = FlattenForEvent(file), PreviousWatermark = previousWatermark }); return(new FileResult(BaseResultStatus.OK, file, previousWatermark)); } catch (Exception ex) { Log(ex); return(new FileResult(BaseResultStatus.INTERNAL_SERVER_ERROR)); } finally { DatabaseLock.ExitWriteLock(); } }