Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4F90DED95 for ; Fri, 15 Mar 2013 15:44:33 +0000 (UTC) Received: (qmail 53633 invoked by uid 500); 15 Mar 2013 15:44:33 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 53550 invoked by uid 500); 15 Mar 2013 15:44:33 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 53538 invoked by uid 99); 15 Mar 2013 15:44:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Mar 2013 15:44:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Mar 2013 15:44:31 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 69BD32388847; Fri, 15 Mar 2013 15:42:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1456990 - in /camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote: FtpOperations.java FtpUtils.java Date: Fri, 15 Mar 2013 15:42:26 -0000 To: commits@camel.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130315154226.69BD32388847@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: davsclaus Date: Fri Mar 15 15:42:25 2013 New Revision: 1456990 URL: http://svn.apache.org/r1456990 Log: CAMEL-6056: Restore camel-ftp to use loigc from working Camel 2.10.2 as otherwise we risk break other stuff for people. Added: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java?rev=1456990&r1=1456989&r2=1456990&view=diff ============================================================================== --- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java (original) +++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java Fri Mar 15 15:42:25 2013 @@ -696,12 +696,8 @@ public class FtpOperations implements Re } // must compact path so FTP server can traverse correctly - String before = path; - char separatorChar = endpoint.getFileSeparator(); - path = FileUtil.compactPath(path, separatorChar); - if (log.isTraceEnabled()) { - log.trace("Compacted path: {} -> {} using separator: {}", new Object[]{before, path, separatorChar}); - } + // use the ftp utils implementation of the compact path + path = FtpUtils.compactPath(path); // not stepwise should change directory in one operation if (!endpoint.getConfiguration().isStepwise()) { Added: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java?rev=1456990&view=auto ============================================================================== --- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java (added) +++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java Fri Mar 15 15:42:25 2013 @@ -0,0 +1,97 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.file.remote; + +import java.io.File; +import java.util.Iterator; +import java.util.Stack; + +import org.apache.camel.util.FileUtil; + +/** + * Various FTP utils. + */ +public final class FtpUtils { + + private FtpUtils() { + } + + /** + * Compacts a path by stacking it and reducing .., + * and uses OS specific file separators (eg {@link java.io.File#separator}). + *

+ * Important: This implementation works for the camel-ftp component + * for various FTP clients and FTP servers using different platforms and whatnot. + * This implementation has been working for many Camel releases, and is included here + * to restore patch compatibility with the Camel releases. + */ + public static String compactPath(String path) { + if (path == null) { + return null; + } + + // only normalize if contains a path separator + if (path.indexOf(File.separator) == -1) { + return path; + } + + // preserve ending slash if given in input path + boolean endsWithSlash = path.endsWith("/") || path.endsWith("\\"); + + // preserve starting slash if given in input path + boolean startsWithSlash = path.startsWith("/") || path.startsWith("\\"); + + Stack stack = new Stack(); + + String separatorRegex = File.separator; + if (FileUtil.isWindows()) { + separatorRegex = "\\\\"; + } + String[] parts = path.split(separatorRegex); + for (String part : parts) { + if (part.equals("..") && !stack.isEmpty() && !"..".equals(stack.peek())) { + // only pop if there is a previous path, which is not a ".." path either + stack.pop(); + } else if (part.equals(".") || part.isEmpty()) { + // do nothing because we don't want a path like foo/./bar or foo//bar + } else { + stack.push(part); + } + } + + // build path based on stack + StringBuilder sb = new StringBuilder(); + + if (startsWithSlash) { + sb.append(File.separator); + } + + for (Iterator it = stack.iterator(); it.hasNext();) { + sb.append(it.next()); + if (it.hasNext()) { + sb.append(File.separator); + } + } + + if (endsWithSlash) { + sb.append(File.separator); + } + + return sb.toString(); + } + +}