Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Fix local path generation (#3432)
Browse files Browse the repository at this point in the history
* Fix local path generation

* format

* fix test
  • Loading branch information
chkeita authored Aug 21, 2023
1 parent 8fc2f83 commit ea4a1ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
29 changes: 0 additions & 29 deletions src/agent/onefuzz-agent/src/log_uploader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,32 +210,3 @@ async fn sync_file(
blob_client.append_block(Body::from(f)).await?;
Ok(len)
}

#[cfg(test)]
mod tests {
use std::io::Seek;

use anyhow::Result;
use tokio::io::{AsyncReadExt, AsyncSeekExt};

#[allow(clippy::unused_io_amount)]
#[tokio::test]
#[ignore]

async fn test_seek_behavior() -> Result<()> {
let path = "C:\\temp\\test.ps1";
let mut std_file = std::fs::File::open(path)?;
std_file.seek(std::io::SeekFrom::Start(3))?;

let mut tokio_file = tokio::fs::File::from_std(std_file);

let buf = &mut [0u8; 5];
tokio_file.read(buf).await?;
println!("******** buf {:?}", buf);
tokio_file.seek(std::io::SeekFrom::Start(0)).await?;
tokio_file.read(buf).await?;
println!("******** buf {:?}", buf);

Ok(())
}
}
23 changes: 19 additions & 4 deletions src/agent/onefuzz/src/blob/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,15 @@ impl BlobContainerUrl {
}

pub fn as_path(&self, prefix: impl AsRef<Path>) -> Result<PathBuf> {
let dir = self
.account()
.ok_or_else(|| anyhow!("Invalid container Url"))?;
Ok(prefix.as_ref().join(dir))
match (self.account(), self.container()) {
(Some(account), Some(container)) => {
let mut path = PathBuf::new();
path.push(account);
path.push(container);
Ok(prefix.as_ref().join(path))
}
_ => bail!("Invalid container Url"),
}
}
}

Expand Down Expand Up @@ -526,4 +531,14 @@ mod tests {
"id:000000,sig:06,src:000000,op:havoc,rep:128"
);
}

#[test]
fn test_as_path() -> Result<()> {
let root = PathBuf::from(r"/onefuzz");
let url = BlobContainerUrl::parse("https://myaccount.blob.core.windows.net/mycontainer")?;
let path = url.as_path(root)?;
assert_eq!(PathBuf::from(r"/onefuzz/myaccount/mycontainer"), path);

Ok(())
}
}

0 comments on commit ea4a1ab

Please sign in to comment.