mirror of
https://github.com/BillyOutlast/posthog.git
synced 2026-02-04 03:01:23 +01:00
feat(cli): delete sourcemaps after upload (#33758)
This commit is contained in:
@@ -62,6 +62,10 @@ pub enum SourcemapCommand {
|
||||
/// disk if not provided.
|
||||
#[arg(long)]
|
||||
version: Option<String>,
|
||||
|
||||
/// Whether to delete the source map files after uploading them
|
||||
#[arg(long, default_value = "false")]
|
||||
delete_after: bool,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -81,12 +85,14 @@ impl Cli {
|
||||
directory,
|
||||
project,
|
||||
version,
|
||||
delete_after,
|
||||
} => {
|
||||
sourcemap::upload::upload(
|
||||
command.host,
|
||||
directory,
|
||||
project.clone(),
|
||||
version.clone(),
|
||||
*delete_after,
|
||||
)?;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -15,6 +15,7 @@ pub fn upload(
|
||||
directory: &PathBuf,
|
||||
project: Option<String>,
|
||||
version: Option<String>,
|
||||
delete_after: bool,
|
||||
) -> Result<()> {
|
||||
let token = load_token().context("While starting upload command")?;
|
||||
let host = token.get_host(host.as_deref());
|
||||
@@ -27,6 +28,10 @@ pub fn upload(
|
||||
);
|
||||
|
||||
let pairs = read_pairs(directory)?;
|
||||
let sourcemap_paths = pairs
|
||||
.iter()
|
||||
.map(|pair| pair.sourcemap.path.clone())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let uploads = collect_uploads(pairs).context("While preparing files for upload")?;
|
||||
info!("Found {} chunks to upload", uploads.len());
|
||||
@@ -48,6 +53,10 @@ pub fn upload(
|
||||
|
||||
upload_chunks(&url, &token.token, uploads, release.as_ref())?;
|
||||
|
||||
if delete_after {
|
||||
delete_files(sourcemap_paths).context("While deleting sourcemaps")?;
|
||||
}
|
||||
|
||||
let _ = capture_handle.join();
|
||||
|
||||
Ok(())
|
||||
@@ -105,3 +114,16 @@ fn content_hash(uploads: &[ChunkUpload]) -> String {
|
||||
}
|
||||
format!("{:x}", hasher.finalize())
|
||||
}
|
||||
|
||||
fn delete_files(paths: Vec<PathBuf>) -> Result<()> {
|
||||
// Delete local sourcemaps files from the sourcepair
|
||||
for path in paths {
|
||||
if path.exists() {
|
||||
std::fs::remove_file(&path).context(format!(
|
||||
"Failed to delete sourcemaps file: {}",
|
||||
path.display()
|
||||
))?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user