Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F0BF9DD5B for ; Thu, 30 May 2013 08:24:21 +0000 (UTC) Received: (qmail 45263 invoked by uid 500); 30 May 2013 08:24:21 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 44551 invoked by uid 500); 30 May 2013 08:24:20 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 44473 invoked by uid 99); 30 May 2013 08:24:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 May 2013 08:24:18 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of bengt.rodehav@gmail.com designates 209.85.192.180 as permitted sender) Received: from [209.85.192.180] (HELO mail-pd0-f180.google.com) (209.85.192.180) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 May 2013 08:24:10 +0000 Received: by mail-pd0-f180.google.com with SMTP id 14so7792835pdc.25 for ; Thu, 30 May 2013 01:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=kR80hAjDEoboiUoJDtj6poGqTXNVIabAejyDq6K2pWw=; b=xPMMhRhIyzAvv3L4RY35+a0IeaxLWXZCzjy9eD7O3FujW56aLVybVWWGQr2FcJ2gZ1 dkWBXb7LPmzGBAX7ru2W9pkFDLEplrayiGbbo/kOKdMs9IV9TdmGs4bTE28gpSkQdhQv lMhUuq/NW4I57ffa7IVkzldnlvRbdUEDvQC6NIRZ9MleweEg7CuMpCszfouYY61QnfhO u/3Pn89bTpJLZhN9KfSavTW0VocpAtlLsYiTjbUN/oiVhygfAB0T/V1NfS3X+FMo31qO mEmhYOzUciKxXmXFXM3YsJwnSMWc8MYd+C7mhLd7oIRxZsupPKB+oTQ0icUddkRS25TD P42g== MIME-Version: 1.0 X-Received: by 10.66.145.229 with SMTP id sx5mr7402230pab.11.1369902228904; Thu, 30 May 2013 01:23:48 -0700 (PDT) Sender: bengt.rodehav@gmail.com Received: by 10.70.7.37 with HTTP; Thu, 30 May 2013 01:23:48 -0700 (PDT) In-Reply-To: References: <5183D4BB.8010001@gmail.com> Date: Thu, 30 May 2013 10:23:48 +0200 X-Google-Sender-Auth: KRtEtW8VSLpzhtRuQa-lc4MoS7Q Message-ID: Subject: Re: Sftp bug in Camel 2.11.0 From: Bengt Rodehav To: users@camel.apache.org Content-Type: multipart/alternative; boundary=047d7b6781b0bb213b04ddeb3770 X-Virus-Checked: Checked by ClamAV on apache.org --047d7b6781b0bb213b04ddeb3770 Content-Type: text/plain; charset=ISO-8859-1 Hello Aki - sorry for the late reply. Yes, I do realize that the reason for this code is to do a stepwise change of directories when going back to the "home" directory. What I don't understand is why this is necessary. It is only done in sftp - not in ftp/ftps. I have never been in any situation where stepwise is needed at all. But, since stepwise by default is true, I assume that these situations exist (but I think the default should be not to use stepwise...). But, why would you have to change directories stepwise when going back up only in sftp but not in ftp/ftps? Also, I always disconnect after each poll (I've found it much more stable) which means that going back up is totally unnecessary since I will re-connect on next poll and therefore start in the "home"directory again. Of course, fixing the logic might be preferrable to removing it if there is a need for this kind of logic... BTW, do you know why the stepwise option exists? What scenario requires us to change to a directory in a stepwise fashion instead of changing to that directory directly? /Bengt 2013/5/27 Aki Yoshida > Hi Bengt, > the quoted code itself is needed for the normal case to ensure the stepwise > operation moves the path upwards from the current directory to where it > started without touching its upper directory which you potentially have no > authorization to access. > > but the code does not handle the case when the path is at the root, as you > describe. In that case, this code needs to be skipped as it is not needed > (because you started out from the root and you have authorization down from > the root to the current directory). > > I commented to the ticket. > > regards, aki > > > 2013/5/6 Bengt Rodehav > > > JIRA created: > > > > https://issues.apache.org/jira/browse/CAMEL-6335 > > > > /Bengt > > > > > > 2013/5/6 Bengt Rodehav > > > > > Hello Hadrian, > > > > > > I'm not really interested in the blame issue. I'm really glad that > there > > > are so many competent people developing Camel which I think is a great > > > product. It might be interesting, though, to see how long the bug has > > been > > > there and what versions are affected. > > > > > > I've also been thinking why it hasn't been picked up by any tests. I > > > realize that it must be very difficult to design tests for integration > > > components like sftp. Ideally you would have a number of ftp/ftps/sftp > > > servers to perform integration tests against. But I guess that is hard > to > > > maintain. I don't think unit tests (with mocking) will catch bugs like > > the > > > above. How are ftp/ftps/sftp integrations tested? > > > > > > I have noticed that some sftp servers silently ignore attempts to > change > > > directory to a non-existing directory - you won't get there but you > won't > > > get an error code either. But some will give you an error code (like > the > > > one we are integrating to right now). > > > > > > I will create a JIRA. As for patching I guess the most important part > is > > > to determine if it is necessary to change back to the home directory > in a > > > stepwise fashion or not. If not, then I think we can just remove that > > code. > > > If it is necessary, then we must instead fix it. > > > > > > /Bengt > > > > > > > > > > > > 2013/5/3 Hadrian Zbarcea > > > > > >> Bengt, many thanks for reporting this. > > >> > > >> Either svn or git tells you pretty quickly how that code got there > (git > > >> blame). Do you mind raising a jira for this embarrassing bug? If you > > want > > >> to contribute a patch it'd be highly appreciated. That aside, I'll > look > > >> into it in the afternoon. I'll need to check if that piece of code was > > >> meant to address another usecase or was an oversight and insufficient > > >> testing. > > >> > > >> Cheers, > > >> Hadrian > > >> > > >> > > >> > > >> On 05/03/2013 10:35 AM, Bengt Rodehav wrote: > > >> > > >>> Unfortunately I seem to have found another bug in Camel 2.11.0 > > regarding > > >>> sftp. I noticed it when I removed the "stepwise=false" argument from > my > > >>> routes thus enabling the default stepwise way of changing directory. > > >>> > > >>> The problematic section begins at line 404 in SftpOperations.java: > > >>> > > >>> *404:* if (getCurrentDirectory().**startsWith(path)) { > > >>> *405:* // use relative path > > >>> *406:* String p = getCurrentDirectory().** > > >>> substring(path.length()); > > >>> *407:* if (p.length() == 0) { > > >>> *408:* return; > > >>> *409:* } > > >>> *410:* // the first character must be '/' and hence > removed > > >>> *411:* path = > > >>> UP_DIR_PATTERN.matcher(p).**replaceAll("/..").substring(1)**; > > >>> *412:* } > > >>> > > >>> > > >>> > > >>> The problem does not arise when stepping down into the directory to > > poll > > >>> but when going back to the directory where we started. Assume that > the > > >>> home > > >>> directory in the sftp server is "/" and I want to poll the directory > > "in" > > >>> relative to the root. My endpoint would look something like this: > > >>> > > >>> sftp://user@server/in?**password=secret > > >>> > > >>> What happens is that the "i" in "in" is removed and Camel attempts to > > >>> change to directory "n". Looking at the code above, the following > > >>> happens: > > >>> > > >>> - The current directory is "/in" since we have previously succeeded > in > > >>> moving there and polling for files. We are now attempting to go back > to > > >>> where we started, therefore "path" is "/". > > >>> - On line 406, the variable "p" will be set to "in", thus removing > the > > >>> leading "/". > > >>> - On line 411 an incorrect assumption is made: It is assumed that the > > >>> first > > >>> character must be "/" but the leading "/" was removed on line 406. > The > > >>> result is therefore that "path" is set to "n" instead of "in". > > >>> > > >>> I haven't investigated when this error was introduced. I did however > > >>> compare with the corresponding logic in FtpOperations.java. In that > > file > > >>> the section quoted above does not exist at all. It seems to me that > the > > >>> purpose with this code is to, stepwise, change directory up to ".." - > > one > > >>> directory at a time instead of going straight to "/". It seems very > > >>> unnecessary to me but I assume there is a reason for it. Otherwise, > the > > >>> easiest change would be to just remove the code above and use the > same > > >>> logic as in FtpOperations.java. > > >>> > > >>> Currently my only workaround is to use "stepwise=false". > > >>> > > >>> /Bengt > > >>> > > >>> > > > > > > --047d7b6781b0bb213b04ddeb3770--