On Thu, 2007-08-23 at 20:57 +0100, Pedro Alves wrote: > >> The rcp you ported doesn't work for me when I try > >> rcp mio:/temp/rshd-log.txt . > >> > > ? > It works here. Why shouldn't it? You're passing an absolute path > to the device. The '.' is the local path. Wrong example, or am I > missing something?
It is in the recursive directory code, as you say below.
> >> The reason is that the remote rcp (the one on the PDA) is compiled with
> >> the mingw32ce toolset, and the libcwd library. That library offers
> >> chdir() and getcwd() but calls to functions like _open() don't have
> >> information from the current directory.
> >>
> >> There are several ways out of this :
> >> 1- add code to rcp.c to deal with this
> >> 2- compile rcp.c with the cegcc toolset which doesn't have this problem
> >> 3- rewrite rcp.c so it doesn't need this
> >>
> >> I feel for 2 because 1 and 3 are reinventing the wheel. Your idea ?
> >>
> >> Danny
> >
> > Grmbl.
> >
> > I tried both 1 and 2. Unfortunately, solution 1 is much less work than
> > solution 2.
> >
>
> That would be my first choice (option 1). Either implement rcp_open
> around libcwd's getcwd, or call getcwd before _open/open. Of the top
> of my head, the case that *may* need it is the recursive directory
> copy, but even then, it may not be needed.
Patch below. I've seen both the receive and send do the wrong thing so I
adapted both.
Danny
--
Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info
Index: rcp.c
===================================================================
--- rcp.c (revision 1047)
+++ rcp.c (working copy)
@@ -242,6 +242,7 @@
/* If the target has wildcards, process them. */
if ((strchr (strPath, '?') != NULL) || (strchr (strPath, '*') != NULL))
{
+ debug("ParseTarget: FindFirstFileA %s\n", strPath);
*hFile = FindFirstFileA (strPath, &wfdFileData);
if (*hFile != INVALID_HANDLE_VALUE)
{
@@ -281,6 +282,7 @@
{
/* Check to see if Target is a file or a directory. */
strcpy (Target, strPath);
+ debug("ParseTarget: stat %s\n", Target);
if (stat (Target, &statbuf) != 0)
return FALSE;
else
@@ -401,6 +403,8 @@
BOOL bTarget;
BOOL bProcessing;
struct _stat statbuf;
+ char fullfn[MAX_PATH];
+ int l;
debug ("sending %s\n", Target);
@@ -484,8 +488,10 @@
return;
}
+ debug("RcpSvrSend: chdir(%s) at %d\n", Target2, __LINE__);
chdir (Target2);
RcpSvrSend ("*", bRecursive);
+ debug("RcpSvrSend: chdir(%s) at %d\n", "..", __LINE__);
chdir ("..");
}
else
@@ -496,11 +502,30 @@
else
{
*FileName = 0;
+ debug("RcpSvrSend: chdir(%s) at %d\n", Target2, __LINE__);
chdir (Target2);
FileName++;
}
/* Open the file for reading. */
- FileId = _open (FileName, O_RDONLY | O_BINARY, S_IWRITE);
+ /* Before we do that, we need to prepend the current directory to
+ * the file name, CE doesn't have that, and our libcwd doesn't
+ * reimplement _open. */
+ if (FileName[0] != '\\' && FileName[0] != '/')
+ {
+ getcwd (fullfn, MAX_PATH+1);
+ l = strlen (fullfn);
+ if (fullfn[l-1] != '/')
+ {
+ fullfn[l] = '/';
+ fullfn[l+1] = '\0';
+ }
+ strcat(fullfn, FileName);
+ FileId = _open (fullfn, O_RDONLY | O_BINARY, S_IWRITE);
+ }
+ else
+ {
+ FileId = _open (FileName, O_RDONLY | O_BINARY, S_IWRITE);
+ }
if (FileId == -1)
{
/* Error condition. */
@@ -668,6 +693,8 @@
BOOL bDir;
BOOL bTarget;
BOOL bProcessing;
+ char fullfn[MAX_PATH]; /* for getcwd workaround */
+ int l;
debug ("RcpSvrRecv\n");
@@ -739,6 +766,7 @@
if (bDir)
{
+ debug("RcpSvrRecv: chdir(%s) at %d\n", Target2, __LINE__);
nValue = chdir (Target2);
if (nValue == -1)
{
@@ -841,9 +869,28 @@
bDir = FALSE;
/* Open the file for writing. */
- FileId =
- _open (Target2, _O_WRONLY | _O_TRUNC | _O_CREAT | _O_BINARY,
- _S_IWRITE);
+ /* Before we do that, we need to prepend the current directory to
+ * the file name, CE doesn't have that, and our libcwd doesn't
+ * reimplement _open. */
+ if (Target2[0] != '\\' && Target2[0] != '/')
+ {
+ getcwd (fullfn, MAX_PATH+1);
+ l = strlen(fullfn);
+ if (fullfn[l-1] != '/')
+ {
+ fullfn[l] = '/';
+ fullfn[l+1] = '\0';
+ }
+ strcat (fullfn, Target2);
+ debug ("open file [%s] for write -> ", fullfn);
+ FileId = _open (fullfn, _O_WRONLY | _O_TRUNC | _O_CREAT | _O_BINARY,
+ _S_IWRITE);
+ }
+ else
+ {
+ FileId = _open (Target2, _O_WRONLY | _O_TRUNC | _O_CREAT | _O_BINARY,
+ _S_IWRITE);
+ }
if (FileId == -1)
{
/* Error condition. */
@@ -1009,6 +1056,7 @@
debug ("closing down\n");
/* Make sure we end up where we started. */
+ debug("rcp_main: chdir(%s) at %d\n", HomeDir, __LINE__);
chdir (HomeDir);
free (HomeDir);
signature.asc
Description: This is a digitally signed message part
------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________ Cegcc-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/cegcc-devel
