Creates a new artifact with the given artifact bytes. If the artifact already exists, the existing artifact id is returned.
(&self, artifact: Vec<u8>)
| 31 | /// |
| 32 | /// If the artifact already exists, the existing artifact id is returned. |
| 33 | pub fn create(&self, artifact: Vec<u8>) -> ServiceResult<ArtifactId> { |
| 34 | let artifact = Artifact::new(artifact); |
| 35 | |
| 36 | match self.artifact_repository.find_by_hash(artifact.hash()) { |
| 37 | Some(artifact_id) => { |
| 38 | let mut artifact = self.find_by_id(&artifact_id)?; |
| 39 | |
| 40 | artifact.increment_rc(); |
| 41 | |
| 42 | self.artifact_repository |
| 43 | .insert(*artifact.id(), artifact.clone()); |
| 44 | |
| 45 | Ok(artifact_id) |
| 46 | } |
| 47 | None => { |
| 48 | let artifact_id = artifact.id(); |
| 49 | |
| 50 | artifact.validate()?; |
| 51 | |
| 52 | self.artifact_repository |
| 53 | .insert(*artifact_id, artifact.clone()); |
| 54 | |
| 55 | Ok(*artifact_id) |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /// Finds an artifact by its id. |
| 61 | /// |