summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2014-03-11 22:31:34 +0700
committerhathach <[email protected]>2014-03-11 22:31:34 +0700
commitf55ae521a0b3ee730af723bbdfd115c28d3d1eda (patch)
tree9f33524d3f5fe6e31d15a5d688f69452601b31bc
parentd2ee92da48633330cbb9dc3b6f957bc140fbce7f (diff)
enhance cp command to accept dest path as an folder
-rw-r--r--demos/host/host_os_none/host_os_none.uvopt14
-rw-r--r--demos/host/host_os_none/host_os_none.uvproj2
-rw-r--r--demos/host/src/cli.c21
3 files changed, 24 insertions, 13 deletions
diff --git a/demos/host/host_os_none/host_os_none.uvopt b/demos/host/host_os_none/host_os_none.uvopt
index e65da83b2..397e398f6 100644
--- a/demos/host/host_os_none/host_os_none.uvopt
+++ b/demos/host/host_os_none/host_os_none.uvopt
@@ -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>
diff --git a/demos/host/host_os_none/host_os_none.uvproj b/demos/host/host_os_none/host_os_none.uvproj
index 06cf0f5e9..7990b6fe8 100644
--- a/demos/host/host_os_none/host_os_none.uvproj
+++ b/demos/host/host_os_none/host_os_none.uvproj
@@ -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>
diff --git a/demos/host/src/cli.c b/demos/host/src/cli.c
index d67379b9b..4cb33e060 100644
--- a/demos/host/src/cli.c
+++ b/demos/host/src/cli.c
@@ -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 -------------//
+ //------------- 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 src_file, dest_file;
+ FIL dest_file;
- if ( FR_OK != f_open(&src_file , p_para, FA_READ) ) return CLI_ERROR_INVALID_PATH;
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;