Skip to content

Commit

Permalink
Use a random name for temp files
Browse files Browse the repository at this point in the history
  • Loading branch information
gsurkov committed Oct 24, 2023
1 parent b5238be commit b204c08
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions applications/main/infrared/infrared_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ static bool infrared_remote_batch_start(
InfraredRemote* remote,
InfraredBatchCallback batch_callback,
const InfraredBatchTarget* target) {
FuriString* tmp = furi_string_alloc();
Storage* storage = furi_record_open(RECORD_STORAGE);

InfraredBatch batch_context = {
Expand All @@ -169,8 +170,15 @@ static bool infrared_remote_batch_start(
};

const char* path_in = furi_string_get_cstr(remote->path);
// TODO: Generate a random file name
const char* path_out = ANY_PATH("infrared/temp.ir.swp");
const char* path_out;

FS_Error status;

do {
furi_string_printf(tmp, "%s.temp%08x.swp", path_in, rand());
path_out = furi_string_get_cstr(tmp);
status = storage_common_stat(storage, path_out, NULL);
} while(status == FSE_OK || status == FSE_EXIST);

bool success = false;

Expand Down Expand Up @@ -203,6 +211,7 @@ static bool infrared_remote_batch_start(
furi_string_free(batch_context.signal_name);
flipper_format_free(batch_context.ff_out);
flipper_format_free(batch_context.ff_in);
furi_string_free(tmp);

furi_record_close(RECORD_STORAGE);

Expand Down

0 comments on commit b204c08

Please sign in to comment.