Skip to content

Commit 29763c9

Browse files
committed
fix command name and check logic
1 parent 07c1cec commit 29763c9

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

agent-control/src/bin/main_agent_control_onhost_cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ enum Commands {
2222
// Generate Agent Control configuration according to the provided configuration data.
2323
GenerateConfig(config_gen::Args),
2424
// Migrate from the older on host folders to the new ones.
25-
MigrateFolders,
25+
FilesBackwardsCompatibilityMigrationFromV120,
2626
}
2727

2828
fn main() -> ExitCode {
@@ -43,7 +43,7 @@ fn main() -> ExitCode {
4343
}
4444
config_gen::generate_config(args)
4545
}
46-
Commands::MigrateFolders => migrate_folders::migrate(),
46+
Commands::FilesBackwardsCompatibilityMigrationFromV120 => migrate_folders::migrate(),
4747
};
4848

4949
if let Err(err) = result {

agent-control/src/cli/on_host/migrate_folders.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ pub fn migrate() -> Result<(), CliError> {
3333
}
3434
Ok(())
3535
}
36-
// Check if the new folders already exists - local-data and fleet-data
36+
// Check if the new folders already exists - local-data or fleet-data
3737
fn check_new_folders(local_new_path: &Path, remote_new_path: &Path) -> bool {
3838
let local_exists = local_new_path.exists() && local_new_path.is_dir();
3939
let fleet_exists = remote_new_path.exists() && remote_new_path.is_dir();
4040

41-
local_exists && fleet_exists
41+
local_exists || fleet_exists
4242
}
4343
// Copy the old files in the new paths but leaving the old ones in place
4444
fn move_and_rename(local_base: &Path, remote_base: &Path) -> Result<(), CliError> {
@@ -156,7 +156,7 @@ fn add_infra_agent_files(
156156
) {
157157
// --- LOCAL ---
158158
let old_local_infra_dir = local_base.join(OLD_SUB_AGENT_DATA_DIR).join(INFRA_AGENT_ID);
159-
if old_local_infra_dir.exists() && old_local_infra_dir.is_dir() {
159+
if old_local_infra_dir.exists() {
160160
debug!(
161161
"Found old local nr-infra directory, adding to migration: {}",
162162
old_local_infra_dir.display()
@@ -177,7 +177,7 @@ fn add_infra_agent_files(
177177
let old_remote_infra_dir = remote_base
178178
.join(OLD_SUB_AGENT_DATA_DIR)
179179
.join(INFRA_AGENT_ID);
180-
if old_remote_infra_dir.exists() && old_remote_infra_dir.is_dir() {
180+
if old_remote_infra_dir.exists() {
181181
debug!(
182182
"Found old remote nr-infra directory, adding to migration: {}",
183183
old_remote_infra_dir.display()
@@ -210,7 +210,7 @@ fn add_otel_agent_files(
210210
) {
211211
// --- LOCAL ---
212212
let old_local_otel_dir = local_base.join(OLD_SUB_AGENT_DATA_DIR).join(OTEL_AGENT_ID);
213-
if old_local_otel_dir.exists() && old_local_otel_dir.is_dir() {
213+
if old_local_otel_dir.exists() {
214214
debug!(
215215
"Found old local nrdot directory, adding to migration: {}",
216216
old_local_otel_dir.display()
@@ -229,7 +229,7 @@ fn add_otel_agent_files(
229229

230230
// --- REMOTE ---
231231
let old_remote_otel_dir = remote_base.join(OLD_SUB_AGENT_DATA_DIR).join(OTEL_AGENT_ID);
232-
if old_remote_otel_dir.exists() && old_remote_otel_dir.is_dir() {
232+
if old_remote_otel_dir.exists() {
233233
debug!(
234234
"Found old remote nrdot directory, adding to migration: {}",
235235
old_remote_otel_dir.display()
@@ -300,21 +300,6 @@ mod tests {
300300
assert!(exists);
301301
}
302302

303-
#[test]
304-
fn test_check_new_folders_false_if_one_is_missing() {
305-
let temp_dir = tempdir().unwrap();
306-
let local_base = temp_dir.path().join("local");
307-
let data_base = temp_dir.path().join("data");
308-
309-
let local_new_path = local_base.join(FOLDER_NAME_LOCAL_DATA);
310-
let remote_new_path = data_base.join(FOLDER_NAME_FLEET_DATA);
311-
312-
fs::create_dir_all(&local_new_path).unwrap();
313-
314-
let exists = check_new_folders(&local_new_path, &remote_new_path);
315-
assert!(!exists);
316-
}
317-
318303
#[test]
319304
fn test_move_item_success() {
320305
let temp_dir = tempdir().unwrap();

build/package/postinstall.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fi
1717
######################################################################################
1818
if command -v newrelic-agent-control-cli >/dev/null 2>&1; then
1919
echo "Running New Relic Agent Control folder migration..."
20-
newrelic-agent-control-cli migrate-folders || true
20+
newrelic-agent-control-cli files-backwards-compatibility-migration-from-v120 || true
2121
else
2222
echo "Warning: newrelic-agent-control-cli not found. Skipping folder migration." >&2
2323
fi

0 commit comments

Comments
 (0)