Remove ending space or dot when copying files from FAT

This commit is contained in:
Christophe Grenier 2018-10-30 19:00:13 +01:00
parent a6da0c4b96
commit 7da08fa5b3
2 changed files with 25 additions and 0 deletions

View file

@ -477,6 +477,17 @@ int set_mode(const char *pathname, unsigned int mode)
#endif
}
static void strip_fn(char *fn)
{
unsigned int i;
for(i=0;fn[i]!='\0';i++);
while(i>0 && (fn[i-1]==' '||fn[i-1]=='.'))
i--;
if(i==0 && (fn[i]==' '||fn[i]=='.'))
fn[i++]='_';
fn[i]='\0';
}
#ifdef DJGPP
static inline unsigned char convert_char_dos(unsigned char car)
{
@ -742,6 +753,7 @@ FILE *fopen_local(char **localfilename, const char *localroot, const char *filen
memcpy(dst, localroot, l1);
memcpy(dst+l1, filename, l2+1);
*localfilename=dst;
strip_fn(dst);
f_out=fopen(dst,"wb");
if(f_out)
return f_out;

View file

@ -138,6 +138,17 @@ static int pfind_sectors_per_cluster(disk_t *disk, partition_t *partition, const
return find_sectors_per_cluster_aux(sector_cluster,nbr_subdir,sectors_per_cluster,offset_org,verbose,partition->part_size/disk->sector_size, UP_UNK);
}
static void strip_fn(char *fn)
{
unsigned int i;
for(i=0; fn[i]!='\0'; i++);
while(i>0 && (fn[i-1]==' ' || fn[i-1]=='.'))
i--;
if(i==0 && (fn[0]==' ' || fn[0]=='.'))
fn[i++]='_';
fn[i]='\0';
}
static int fat_copy_file(disk_t *disk, const partition_t *partition, const unsigned int cluster_size, const uint64_t start_data, const char *recup_dir, const unsigned int dir_num, const unsigned int inode_num, const file_info_t *file)
{
char *new_file;
@ -158,12 +169,14 @@ static int fat_copy_file(disk_t *disk, const partition_t *partition, const unsig
#endif
snprintf(new_file, 1024, "%s.%u/inode_%u/%s", recup_dir, dir_num, inode_num,
file->name);
strip_fn(new_file);
if((f_out=fopen(new_file, "rb"))!=NULL)
{
fclose(f_out);
snprintf(new_file, 1024, "%s.%u/inode_%u/f%07u-%s", recup_dir, dir_num, inode_num,
(unsigned int)((start_data - partition->part_offset + (uint64_t)(cluster-2)*cluster_size)/disk->sector_size),
file->name);
strip_fn(new_file);
}
log_info("fat_copy_file %s\n", new_file);
f_out=fopen(new_file, "wb");