feat: if hardlink failed, remove the file and copy to output path (#214)
Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
parent
d06f375dbd
commit
15eaac46e7
|
|
@ -61,9 +61,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstream"
|
name = "anstream"
|
||||||
version = "0.6.5"
|
version = "0.6.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6"
|
checksum = "4cd2405b3ac1faab2990b74d728624cd9fd115651fcecc7c2d8daf01376275ba"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstyle",
|
"anstyle",
|
||||||
"anstyle-parse",
|
"anstyle-parse",
|
||||||
|
|
@ -220,9 +220,9 @@ checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "base64"
|
name = "base64"
|
||||||
version = "0.21.6"
|
version = "0.21.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c79fed4cdb43e993fcdadc7e58a09fd0e3e649c4436fa11da71c9f1f3ee7feb9"
|
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bindgen"
|
name = "bindgen"
|
||||||
|
|
@ -348,9 +348,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.4.14"
|
version = "4.4.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "33e92c5c1a78c62968ec57dbc2440366a2d6e5a23faf829970ff1585dc6b18e2"
|
checksum = "58e54881c004cec7895b0068a0a954cd5d62da01aef83fa35b1e594497bf5445"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap_builder",
|
"clap_builder",
|
||||||
"clap_derive",
|
"clap_derive",
|
||||||
|
|
@ -358,9 +358,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_builder"
|
name = "clap_builder"
|
||||||
version = "4.4.14"
|
version = "4.4.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f4323769dc8a61e2c39ad7dc26f6f2800524691a44d74fe3d1071a5c24db6370"
|
checksum = "59cb82d7f531603d2fd1f507441cdd35184fa81beff7bd489570de7f773460bb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstream",
|
"anstream",
|
||||||
"anstyle",
|
"anstyle",
|
||||||
|
|
@ -523,9 +523,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dragonfly-api"
|
name = "dragonfly-api"
|
||||||
version = "2.0.78"
|
version = "2.0.79"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "358cffc9a9b0b2f0e08496b9c6e3fd044a916d1a3139760a27fcf60120deba3b"
|
checksum = "64e10ea493515e43f502f96ead4fb3e0a649de94b9863c84f4375a1e4fefffdb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"prost 0.11.9",
|
"prost 0.11.9",
|
||||||
"prost-types 0.12.3",
|
"prost-types 0.12.3",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "dragonfly-client"
|
name = "dragonfly-client"
|
||||||
version = "0.1.12"
|
version = "0.1.13"
|
||||||
authors = ["The Dragonfly Developers"]
|
authors = ["The Dragonfly Developers"]
|
||||||
homepage = "https://d7y.io/"
|
homepage = "https://d7y.io/"
|
||||||
repository = "https://github.com/dragonflyoss/client.git"
|
repository = "https://github.com/dragonflyoss/client.git"
|
||||||
|
|
@ -55,7 +55,7 @@ local-ip-address = "0.5.3"
|
||||||
rocksdb = "0.21.0"
|
rocksdb = "0.21.0"
|
||||||
num_cpus = "1.0"
|
num_cpus = "1.0"
|
||||||
chrono = { version = "0.4.26", features = ["serde"] }
|
chrono = { version = "0.4.26", features = ["serde"] }
|
||||||
dragonfly-api = "2.0.78"
|
dragonfly-api = "2.0.79"
|
||||||
sysinfo = "0.29.6"
|
sysinfo = "0.29.6"
|
||||||
sha2 = "0.10"
|
sha2 = "0.10"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
|
|
|
||||||
|
|
@ -245,7 +245,7 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
filters: args.filters.unwrap_or_default(),
|
filters: args.filters.unwrap_or_default(),
|
||||||
header: parse_header(args.header.unwrap_or_default())?,
|
header: parse_header(args.header.unwrap_or_default())?,
|
||||||
piece_length: args.piece_length,
|
piece_length: args.piece_length,
|
||||||
output_path: args.output.into_os_string().into_string().unwrap(),
|
output_path: Some(args.output.into_os_string().into_string().unwrap()),
|
||||||
timeout: Some(prost_wkt_types::Duration::try_from(args.timeout)?),
|
timeout: Some(prost_wkt_types::Duration::try_from(args.timeout)?),
|
||||||
need_back_to_source: false,
|
need_back_to_source: false,
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
|
|
@ -247,23 +247,27 @@ impl DfdaemonDownload for DfdaemonDownloadServerHandler {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hard link or copy the task content to the destination.
|
// Check whether the output path is empty. If output path is empty,
|
||||||
if let Err(err) = task
|
// should not hard link or copy the task content to the destination.
|
||||||
.hard_link_or_copy(
|
if let Some(output_path) = download.output_path.clone() {
|
||||||
task_id.as_str(),
|
// Hard link or copy the task content to the destination.
|
||||||
Path::new(download.output_path.clone().as_str()),
|
if let Err(err) = task
|
||||||
download.range.clone(),
|
.hard_link_or_copy(
|
||||||
)
|
task_id.as_str(),
|
||||||
.await
|
Path::new(output_path.as_str()),
|
||||||
{
|
download.range.clone(),
|
||||||
error!("hard link or copy task: {}", err);
|
)
|
||||||
out_stream_tx
|
|
||||||
.send(Err(Status::internal(err.to_string())))
|
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|err| {
|
{
|
||||||
error!("send download progress error: {:?}", err);
|
error!("hard link or copy task: {}", err);
|
||||||
});
|
out_stream_tx
|
||||||
};
|
.send(Err(Status::internal(err.to_string())))
|
||||||
|
.await
|
||||||
|
.unwrap_or_else(|err| {
|
||||||
|
error!("send download progress error: {:?}", err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// Download task failed.
|
// Download task failed.
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::config;
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
use dragonfly_api::common::v2::Range;
|
use dragonfly_api::common::v2::Range;
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
|
|
@ -46,7 +45,7 @@ pub struct WritePieceResponse {
|
||||||
impl Content {
|
impl Content {
|
||||||
// new returns a new content.
|
// new returns a new content.
|
||||||
pub async fn new(dir: &Path) -> Result<Content> {
|
pub async fn new(dir: &Path) -> Result<Content> {
|
||||||
let dir = dir.join(config::NAME).join(DEFAULT_DIR_NAME);
|
let dir = dir.join(DEFAULT_DIR_NAME);
|
||||||
fs::create_dir_all(&dir).await?;
|
fs::create_dir_all(&dir).await?;
|
||||||
info!("content initialized directory: {:?}", dir);
|
info!("content initialized directory: {:?}", dir);
|
||||||
|
|
||||||
|
|
@ -68,11 +67,12 @@ impl Content {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the task content to the destination. If the hard link fails,
|
// If the hard link fails,
|
||||||
// copy the task content to the destination.
|
// copy the task content to the destination.
|
||||||
if let Err(err) = self.hard_link_task(task_id, to).await {
|
if let Err(err) = self.hard_link_task(task_id, to).await {
|
||||||
info!("hard link task failed: {}", err);
|
info!("hard link task failed: {}", err);
|
||||||
|
|
||||||
|
fs::remove_file(to).await?;
|
||||||
self.copy_task(task_id, to).await?;
|
self.copy_task(task_id, to).await?;
|
||||||
info!("copy task success");
|
info!("copy task success");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::config;
|
|
||||||
use crate::{Error, Result};
|
use crate::{Error, Result};
|
||||||
use chrono::{NaiveDateTime, Utc};
|
use chrono::{NaiveDateTime, Utc};
|
||||||
use rocksdb::{
|
use rocksdb::{
|
||||||
|
|
@ -209,7 +208,7 @@ impl Metadata {
|
||||||
options.set_block_based_table_factory(&block_options);
|
options.set_block_based_table_factory(&block_options);
|
||||||
|
|
||||||
// Open rocksdb.
|
// Open rocksdb.
|
||||||
let dir = dir.join(config::NAME).join(DEFAULT_DIR_NAME);
|
let dir = dir.join(DEFAULT_DIR_NAME);
|
||||||
let cf_names = [TASK_CF_NAME, PIECE_CF_NAME];
|
let cf_names = [TASK_CF_NAME, PIECE_CF_NAME];
|
||||||
let db =
|
let db =
|
||||||
TransactionDB::open_cf(&options, &TransactionDBOptions::default(), &dir, cf_names)?;
|
TransactionDB::open_cf(&options, &TransactionDBOptions::default(), &dir, cf_names)?;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue