aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyun Jae Moon <hyunjaemoon@google.com>2023-04-19 23:23:13 +0000
committerHyun Jae Moon <hyunjaemoon@google.com>2023-04-20 00:20:05 +0000
commitcb93df622269d6e05548d2a65ee0002aff65141f (patch)
tree28d8bbeb4276af61b50a99b3dba28a11d522ab56
parentc94195a9127314edbea582e4b94434fa96ce3e5a (diff)
downloadnetsim-cb93df622269d6e05548d2a65ee0002aff65141f.tar.gz
Clear old pcap files in temp directory on startup
Bug: 274684162 Change-Id: Ia25afe7484ce7c4a49169e328ae9b0f7d65d58c9
-rw-r--r--rust/netsim-cxx/src/captures/handlers.rs14
-rw-r--r--rust/netsim-cxx/src/lib.rs8
-rw-r--r--src/core/server.cc5
3 files changed, 26 insertions, 1 deletions
diff --git a/rust/netsim-cxx/src/captures/handlers.rs b/rust/netsim-cxx/src/captures/handlers.rs
index 3dc6c37b..1c2833c5 100644
--- a/rust/netsim-cxx/src/captures/handlers.rs
+++ b/rust/netsim-cxx/src/captures/handlers.rs
@@ -352,3 +352,17 @@ pub fn handle_packet_request(kind: u32, facade_id: u32, packet: &CxxVector<u8>,
pub fn handle_packet_response(kind: u32, facade_id: u32, packet: &CxxVector<u8>, packet_type: u32) {
handle_packet(kind, facade_id, packet, packet_type, PacketDirection::ControllerToHost)
}
+
+// Cxx Method for clearing pcap files in temp directory
+pub fn clear_pcap_files() -> bool {
+ let mut path = std::env::temp_dir();
+ path.push("netsim-pcaps");
+
+ // Check if the directory exists.
+ if std::fs::metadata(&path).is_err() {
+ return false;
+ }
+
+ // Delete the directory.
+ std::fs::remove_dir_all(&path).is_ok()
+}
diff --git a/rust/netsim-cxx/src/lib.rs b/rust/netsim-cxx/src/lib.rs
index 22cb7c92..4fda715a 100644
--- a/rust/netsim-cxx/src/lib.rs
+++ b/rust/netsim-cxx/src/lib.rs
@@ -35,7 +35,7 @@ use crate::transport::fd::handle_response;
use crate::transport::fd::run_fd_transport;
use crate::captures::handlers::{
- handle_capture_cxx, handle_packet_request, handle_packet_response,
+ clear_pcap_files, handle_capture_cxx, handle_packet_request, handle_packet_response,
};
use crate::http_server::run_http_server;
use crate::ranging::*;
@@ -99,6 +99,12 @@ mod ffi {
packet_type: u32,
);
+ // Clearing out all pcap Files in temp directory
+
+ #[cxx_name = ClearPcapFiles]
+ #[namespace = "netsim::pcap"]
+ fn clear_pcap_files() -> bool;
+
// Uwb Facade.
#[cxx_name = HandleUwbRequestCxx]
diff --git a/src/core/server.cc b/src/core/server.cc
index 5a484128..371f1014 100644
--- a/src/core/server.cc
+++ b/src/core/server.cc
@@ -72,6 +72,11 @@ std::unique_ptr<grpc::Server> RunGrpcServer(int netsim_grpc_port) {
} // namespace
void Run() {
+ // Clear all pcap files in temp directory
+ if (netsim::pcap::ClearPcapFiles()) {
+ BtsLog("netsim generated pcap files in temp directory has been removed.");
+ }
+
// Environment variable "NETSIM_GRPC_PORT" is set in google3 forge. If set:
// 1. Use the fixed port for grpc server.
// 2. Don't start http server.