A fork of attic a self-hostable Nix Binary Cache server
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

server/upload_path: Code smell

+24 -31
+24 -31
server/src/api/v1/upload_path.rs
··· 180 180 let username = req_state.auth.username().map(str::to_string); 181 181 182 182 // Try to acquire a lock on an existing NAR 183 - let existing_nar = database.find_and_lock_nar(&upload_info.nar_hash).await?; 184 - match existing_nar { 185 - Some(existing_nar) => { 186 - // Deduplicate? 187 - let missing_chunk = ChunkRef::find() 188 - .filter(chunkref::Column::NarId.eq(existing_nar.id)) 189 - .filter(chunkref::Column::ChunkId.is_null()) 190 - .limit(1) 191 - .one(database) 192 - .await 193 - .map_err(ServerError::database_error)?; 183 + if let Some(existing_nar) = database.find_and_lock_nar(&upload_info.nar_hash).await? { 184 + // Deduplicate? 185 + let missing_chunk = ChunkRef::find() 186 + .filter(chunkref::Column::NarId.eq(existing_nar.id)) 187 + .filter(chunkref::Column::ChunkId.is_null()) 188 + .limit(1) 189 + .one(database) 190 + .await 191 + .map_err(ServerError::database_error)?; 194 192 195 - if missing_chunk.is_some() { 196 - // Need to repair 197 - upload_path_new(username, cache, upload_info, stream, database, &state).await 198 - } else { 199 - // Can actually be deduplicated 200 - upload_path_dedup( 201 - username, 202 - cache, 203 - upload_info, 204 - stream, 205 - database, 206 - &state, 207 - existing_nar, 208 - ) 209 - .await 210 - } 211 - } 212 - None => { 213 - // New NAR 214 - upload_path_new(username, cache, upload_info, stream, database, &state).await 193 + if missing_chunk.is_none() { 194 + // Can actually be deduplicated 195 + return upload_path_dedup( 196 + username, 197 + cache, 198 + upload_info, 199 + stream, 200 + database, 201 + &state, 202 + existing_nar, 203 + ) 204 + .await; 215 205 } 216 206 } 207 + 208 + // New NAR or need to repair 209 + upload_path_new(username, cache, upload_info, stream, database, &state).await 217 210 } 218 211 219 212 /// Uploads a path when there is already a matching NAR in the global cache.