enhance cp command to accept dest path as an folder

This commit is contained in:
hathach 2014-03-11 22:31:34 +07:00
parent d2ee92da48
commit f55ae521a0
3 changed files with 25 additions and 14 deletions

View File

@ -761,7 +761,7 @@
<tDllPa></tDllPa>
<tDlgDll></tDlgDll>
<tDlgPa></tDlgPa>
<tIfile>.\keil_ram.ini</tIfile>
<tIfile>..\..\bsp\lpc43xx\keil_ram.ini</tIfile>
<pMon>Segger\JL2CM3.dll</pMon>
</DebugOpt>
<TargetDriverDllRegistry>
@ -1428,7 +1428,7 @@
<Focus>0</Focus>
<ColumnNumber>39</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg>
<TopLine>58</TopLine>
<TopLine>59</TopLine>
<CurrentLine>63</CurrentLine>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\vendor\fatfs\diskio.c</PathWithFileName>
@ -1444,8 +1444,8 @@
<Focus>0</Focus>
<ColumnNumber>11</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg>
<TopLine>2114</TopLine>
<CurrentLine>2121</CurrentLine>
<TopLine>2115</TopLine>
<CurrentLine>2122</CurrentLine>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\vendor\fatfs\ff.c</PathWithFileName>
<FilenameWithoutPath>ff.c</FilenameWithoutPath>
@ -1516,7 +1516,7 @@
<Focus>0</Focus>
<ColumnNumber>17</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg>
<TopLine>83</TopLine>
<TopLine>84</TopLine>
<CurrentLine>90</CurrentLine>
<bDave2>0</bDave2>
<PathWithFileName>..\..\bsp\boards\printf_retarget.c</PathWithFileName>
@ -1652,7 +1652,7 @@
<Focus>0</Focus>
<ColumnNumber>13</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg>
<TopLine>170</TopLine>
<TopLine>171</TopLine>
<CurrentLine>174</CurrentLine>
<bDave2>0</bDave2>
<PathWithFileName>..\..\bsp\lpc43xx\startup_keil\startup_LPC43xx.s</PathWithFileName>
@ -1868,7 +1868,7 @@
<Focus>0</Focus>
<ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg>
<TopLine>140</TopLine>
<TopLine>141</TopLine>
<CurrentLine>145</CurrentLine>
<bDave2>0</bDave2>
<PathWithFileName>..\..\bsp\lpc175x_6x\startup_keil\startup_LPC17xx.s</PathWithFileName>

View File

@ -2462,7 +2462,7 @@
<CpuDllArguments></CpuDllArguments>
<PeripheralDll></PeripheralDll>
<PeripheralDllArguments></PeripheralDllArguments>
<InitializationFile>.\keil_ram.ini</InitializationFile>
<InitializationFile>..\..\bsp\lpc43xx\keil_ram.ini</InitializationFile>
<Driver>Segger\JL2CM3.dll</Driver>
</TargetDlls>
</DebugOption>

View File

@ -396,19 +396,30 @@ cli_error_t cli_cmd_copy(char *p_para)
drive_letter2number(p_para);
drive_letter2number(p_dest);
//------------- Check Existence of source & dest file -------------//
cli_error_t error = CLI_ERROR_NONE;
FIL src_file, dest_file;
//------------- Check Existence of source file -------------//
FIL src_file;
if ( FR_OK != f_open(&src_file , p_para, FA_READ) ) return CLI_ERROR_INVALID_PATH;
//------------- Check if dest path is a folder or a non-existing file (overwritten is not allowed) -------------//
FILINFO dest_entry;
if ( (f_stat(p_dest, &dest_entry) == FR_OK) && (dest_entry.fattrib & AM_DIR) )
{ // the destination is an existed folder --> auto append dest filename to be the folder
strcat(p_dest, "/");
strcat(p_dest, p_para);
}
//------------- Open dest file and start the copy -------------//
cli_error_t error = CLI_ERROR_NONE;
FIL dest_file;
switch ( f_open(&dest_file, p_dest, FA_WRITE | FA_CREATE_NEW) )
{
case FR_EXIST:
error = CLI_ERROR_FILE_EXISTED;
break;\
break;
case FR_OK:
while(1)
while(1) // copying
{
uint32_t bytes_read = 0;
uint32_t bytes_write = 0;