@@ -208,24 +208,44 @@ mod private
208208
209209 //
210210
211- /// Determines whether a package needs to be published by comparing `.crate` files from the local and remote package .
211+ /// Determines if a package needs to be published by comparing its local `.crate` file against the version on crates.io .
212212 ///
213- /// This function requires the local package to be previously packed.
213+ /// This function first locates the local, pre-packaged `.crate` file and then attempts to download
214+ /// the corresponding version from the remote registry. It returns `true` if there are differences
215+ /// or if the remote version does not exist (implying a new version to be published).
214216 ///
215- /// # Returns :
216- /// - `true` if the package needs to be published.
217- /// - `false` if there is no need to publish the package.
217+ /// **Prerequisite**: The local package must have been packaged beforehand (e.g., using `cargo package`).
218+ ///
219+ /// # Arguments
220+ ///
221+ /// * `package` - A reference to the `Package` struct for which the check is being performed.
222+ /// * `path` - An optional path to a directory that contains the packaged `.crate` file.
223+ /// If `Some`, this path is used directly. If `None`, the path is constructed using `target_dir`.
224+ /// * `target_dir` - The path to the workspace's `target` directory, used to find the
225+ /// local `.crate` file if a specific `path` is not provided.
226+ ///
227+ /// # Returns
228+ ///
229+ /// - `Ok(true)` if the local and remote `.crate` files have differences, or if the package
230+ /// version does not exist on crates.io (e.g., a 403 Forbidden error is received).
231+ /// - `Ok(false)` if the local and remote packages are identical.
218232 ///
219- /// Panics if the package is not loaded or local package is not packed.
220233 /// # Errors
221- /// qqq: doc
222- pub fn publish_need ( package : & Package < ' _ > , path : Option < path:: PathBuf > ) -> Result < bool , PackageError >
234+ ///
235+ /// This function will return an error in the following cases:
236+ ///
237+ /// - `PackageError::LocalPath`: If the path to the local `.crate` file cannot be determined.
238+ /// - `PackageError::ReadArchive`: If the local `.crate` file exists but cannot be read.
239+ /// - `PackageError::LoadRemotePackage`: If downloading the remote package fails for reasons
240+ /// other than a non-existent version (e.g., network issues).
241+ /// - Any error that occurs while trying to read the package's name or version.
242+ pub fn publish_need ( package : & Package < ' _ > , path : Option < path:: PathBuf > , target_dir : & std:: path:: Path ) -> Result < bool , PackageError >
223243 {
224244 let name = package. name ( ) ?;
225245 let version = package. version ( ) ?;
226246 let local_package_path = path
227247 . map ( | p | p. join ( format ! ( "package/{name}-{version}.crate" ) ) )
228- . unwrap_or ( packed_crate:: local_path ( name, & version, package . crate_dir ( ) ) . map_err ( | _ | PackageError :: LocalPath ) ? ) ;
248+ . unwrap_or ( packed_crate:: local_path ( name, & version, target_dir ) . map_err ( | _ | PackageError :: LocalPath ) ? ) ;
229249
230250 let local_package = CrateArchive :: read ( local_package_path ) . map_err ( | _ | PackageError :: ReadArchive ) ?;
231251 let remote_package = match CrateArchive :: download_crates_io ( name, version )
0 commit comments