Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions gtest/mega65_ftp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,61 @@ TEST_F(Mega65FtpTestFixture, CreateDeleteDirectoryWithFiles)
EXPECT_THAT(output, testing::ContainsRegex("253 out of 256 Cluster"));
}

TEST_F(Mega65FtpTestFixture, PutDeleteDirectorystructureWithFiles)
{
char *topleveldir = "test_dir_on_top_level";
char *subleveldir = "sub_directory_test";
char *subsubleveldir = "subsub_directory_test";
char *longfilename = "LongFileName.d81";

init_sdcard_data();

ReleaseStdOut();
CaptureStdOut();
show_directory("");
std::string output = RetrieveStdOut();
EXPECT_THAT(output, testing::ContainsRegex(" 0 File"));
// also check for the before amount of regained available clusters:
EXPECT_THAT(output, testing::ContainsRegex("253 out of 256 Cluster"));

ReleaseStdOut();
CaptureStdOut();

create_dir(topleveldir);
change_dir(topleveldir);
generate_dummy_file_embed_name(longfilename, 4096);

// go one level deeper:
create_dir(subleveldir);
change_dir(subleveldir);
generate_dummy_file_embed_name(longfilename, 4096);

// go one level deeper:
create_dir(subleveldir);
change_dir(subleveldir);
generate_dummy_file_embed_name(longfilename, 4096);

// dump_sdcard_to_file("sdcard_after1.bin");

// perform this on the directory now:
change_dir("/");
// upload the directory structure as a whole:
upload_file(topleveldir, topleveldir);

// this replaces: delete_file_or_dir(topleveldir);
testWithSimulatedInput(delete_file_or_dir, topleveldir, "y\n");

// now assess that dir-entries have been removed

// dump_sdcard_to_file("sdcard_after2.bin");

show_directory("");
/* std::string */ output = RetrieveStdOut();
EXPECT_THAT(output, testing::ContainsRegex(" 0 File"));
// also check for the before amount of regained available clusters:
EXPECT_THAT(output, testing::ContainsRegex("253 out of 256 Cluster"));
}

TEST_F(Mega65FtpTestFixture, RenameLFNToAnotherLFNShouldRenameLFNAndShortNameDirEntries)
{
init_sdcard_data();
Expand Down
45 changes: 40 additions & 5 deletions src/tools/mega65_ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4679,6 +4679,13 @@ int upload_single_file(char *name, char *dest_name)
BOOL file_exists = find_file_in_curdir(dest_name, &de);

if (file_exists) {
// skipping already existing files if 'y' option to skip user consent
// is used as suggested by Tayger:
if (ignore_security_questions) {
printf("%s already existing, skip option 'y' given, skipping...\n", dest_name);
return 0;
}

// assess how many contiguous clusters it consumes right now.
int is_frag = is_fragmented(dest_name);
int num_clusters = get_cluster_count(dest_name);
Expand All @@ -4704,8 +4711,7 @@ int upload_single_file(char *name, char *dest_name)

if (dir_sector == -1) {
printf("ERROR: Drive is full.\n");
retVal = -1;
break;
return -1;
}
else {
// printf("Directory entry is at offset $%03x of sector $%x\n",dir_sector_offset,dir_sector);
Expand Down Expand Up @@ -4849,19 +4855,46 @@ int upload_file(char *name, char *dest_name)

// if no wildcards in name, then just upload a single file
if (!strstr(name, "*"))
{
d = opendir(name);
if ((d) && ((dir = readdir(d)) != NULL)) {
printf("\nCreating remote directory \"%s\"...\n", dest_name);
// if option 'y' to skip user consent on overwriting is set diving into
// directories to add non existing files and structures is desired as
// suggested by Tayger:
if (create_dir(dest_name) != 0 && !ignore_security_questions) return -1;
change_dir(dest_name);
change_local_dir(name);
// recursion within the directory:
upload_file("*", "*");
change_dir("..");
change_local_dir("..");
closedir(d);
return 0;
}
closedir(d);
// it is not a directory:
return upload_single_file(name, dest_name);
}

// check for wildcards in name
// list directory first
d = opendir(".");
if (d) {
while ((dir = readdir(d)) != NULL) {
if (!is_match(dir->d_name, name, 1))
// skip directory management entries and non matching ones:
if ((strcmp(dir->d_name, "..") == 0) ||
(strcmp(dir->d_name, ".") == 0) ||
(!is_match(dir->d_name, name, 1)))
continue;

struct stat file_stats;
if (!stat(dir->d_name, &file_stats)) {
if (!S_ISDIR(file_stats.st_mode)) {
if (S_ISDIR(file_stats.st_mode)) {
// printf("\nrecursing for directory \"%s\"...\n", dir->d_name);
// recursion for a directory:
upload_file(dir->d_name, dir->d_name);
} else {
printf("\nUploading \"%s\"...\n", dir->d_name);
upload_single_file(dir->d_name, dir->d_name);
}
Expand Down Expand Up @@ -4921,7 +4954,9 @@ int create_dir(char *dest_name)

BOOL file_exists = contains_file_or_dir(dest_name);
if (file_exists) {
fprintf(stderr, "ERROR: File or directory '%s' already exists.\n", dest_name);
fprintf(stderr, "%s: File or directory '%s' already exists.\n",
(ignore_security_questions ? "WARNING" : "ERROR"),
dest_name);
retVal = -1;
break;
}
Expand Down
Loading