File with non-printable characters in name can not be removed

jseifert

Dabbler
Joined
Aug 22, 2022
Messages
16
i think i will need to test that in a VM because this seems scary for an inexperienced c user :D .
 

jseifert

Dabbler
Joined
Aug 22, 2022
Messages
16
ok i tried it with unlink(dp->d_name) but it did not help:
Code:
# ~/a.out
unlink: 256760��m���-452d-a9dc-12c020b9db60.tiff
-1
2


the code i used looks like this:
Code:
#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#include <errno.h>

int main()
{
        DIR *dir;
        struct dirent *dp;
        char * file_name;
        dir = opendir(".");
        int i = 0;
        while ((dp=readdir(dir)) != NULL) {
                i++;
                if ( i == 3 ) {
                        int ret;
                        ret = unlink(dp->d_name);
                        int errsv = errno;
                        printf("unlink: %s\n", dp->d_name);
                        printf("%i\n%i\n", ret, errsv);
                }
        }
        closedir(dir);
        return 0;
}


i == 3 is the first file besides . and ..
errno == 2 means "ENOENT No such file or directory."
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
OK. Thanks for reporting back. Out of ideas.

Of course there's always brute force. Create a new dataset, move all data in that corrupt dataset to the new one. Rename all child datasets (if present) to have the new dataset as parent. Double check. Triple check. Destroy dataset.
 

jseifert

Dabbler
Joined
Aug 22, 2022
Messages
16
OK. Thanks for reporting back. Out of ideas.

Of course there's always brute force. Create a new dataset, move all data in that corrupt dataset to the new one. Rename all child datasets (if present) to have the new dataset as parent. Double check. Triple check. Destroy dataset.
Yeah that was kind of my first idea but i really wanted to avoid that because this dataset is HUGE (>100M files), so copying it would take a week at least.
 
Top