Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Escape file name
Escape file name [message #1420969] Wed, 10 September 2014 19:09 Go to next message
Dol Bik is currently offline Dol BikFriend
Messages: 9
Registered: April 2014
Junior Member
I'm trying to crawl a GitHub Wiki with JGit.
When I try it with one URL, it worked perfectly fine. Then I tried it with another random URL and got an error.
Please see the extract of my code:

import java.io.File;
import java.io.IOException;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;

public class Main {
    // with this URL I get an error
    String url = "https://github.com/radiant/radiant.wiki.git";
    // this URL works
    // String url = "https://github.com/WardCunningham/Smallest-Federated-Wiki.wiki.git";

    public static void main(String[] args) {
        Main m = new Main();
        m.jgitTest();
        System.out.println("Done!");
    }

    public void jgitTest() {
        try {
            File localPath = File.createTempFile("TestGitRepository", "");
            localPath.delete();
            Git.cloneRepository().setURI(url).setDirectory(localPath).call();
        } catch (IOException | GitAPIException e) {
            System.err.println("excepton: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

This is the stack trace:
Exception in thread "main" org.eclipse.jgit.dircache.InvalidPathException: Invalid path (contains separator ':'): How-To:-Create-an-Extension.textile
    at org.eclipse.jgit.dircache.DirCacheCheckout.checkValidPathSegment(DirCacheCheckout.java:1243)
    at org.eclipse.jgit.dircache.DirCacheCheckout.checkValidPathSegment(DirCacheCheckout.java:1225)
    at org.eclipse.jgit.dircache.DirCacheCheckout.checkValidPath(DirCacheCheckout.java:1185)
    at org.eclipse.jgit.dircache.DirCacheCheckout.processEntry(DirCacheCheckout.java:311)
    at org.eclipse.jgit.dircache.DirCacheCheckout.prescanOneTree(DirCacheCheckout.java:290)
    at org.eclipse.jgit.dircache.DirCacheCheckout.doCheckout(DirCacheCheckout.java:408)
    at org.eclipse.jgit.dircache.DirCacheCheckout.checkout(DirCacheCheckout.java:393)
    at org.eclipse.jgit.api.CloneCommand.checkout(CloneCommand.java:236)
    at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:127)
    at Main.jgitTest(Main.java:21)
    at Main.main(Main.java:13)

If you visit the wiki page of the URL that doesn't work (https://github.com/radiant/radiant/wiki), you will find this page: How To: Create an Extension.
The title of this page is the cause of the error:
Invalid path (contains separator ':'): How-To:-Create-an-Extension.textile


I assume I need to escape the file names.
Re: Escape file name [message #1421003 is a reply to message #1420969] Wed, 10 September 2014 20:23 Go to previous messageGo to next message
Christian Halstrick is currently offline Christian HalstrickFriend
Messages: 264
Registered: July 2009
Senior Member
Native git on windows fails with the same error. The reason is clear: This repo contains a file named "./How-To:-Create-an-Extension.textile". That's an ok filename on linux. Native git and jgit can clone that repo on linux. But that filename is invalid for windows filesystems (I guess because of the ':'). Both, native git and jgit can't create a file with that name on a windows filesystem. Therefore the checkout fails. You simply cannot work with repos which contain windows-incompatible filenames on a windows box. Either remove/rename that file or move to a linux box.

Ciao
Chris
Re: Escape file name [message #1421062 is a reply to message #1421003] Wed, 10 September 2014 22:21 Go to previous messageGo to next message
Dol Bik is currently offline Dol BikFriend
Messages: 9
Registered: April 2014
Junior Member
Ok, now I understand, why it works on Linux.
Is there any chance to "escape" special characters in the file names on Windows?
Re: Escape file name [message #1421304 is a reply to message #1421062] Thu, 11 September 2014 07:32 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1101
Registered: July 2009
Senior Member
ObjectChecker forbids ':' in path names on Windows:
http://git.eclipse.org/c/jgit/jgit.git/tree/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java#n527
Re: Escape file name [message #1421347 is a reply to message #1421304] Thu, 11 September 2014 08:41 Go to previous messageGo to next message
Christian Halstrick is currently offline Christian HalstrickFriend
Messages: 264
Registered: July 2009
Senior Member
No chance. Open Windows Notepad, type in a text and select "File->Save As..." and enter "name:a:b:c.txt". Notepad will return an error. On windows those filenames are disallowed. And there is no feature that I know of that you can tell git/jgit to write a file named "name:a:b:c.txt" into a file with different name.


Ciao
Chris
Re: Escape file name [message #1421483 is a reply to message #1421347] Thu, 11 September 2014 12:27 Go to previous messageGo to next message
Dol Bik is currently offline Dol BikFriend
Messages: 9
Registered: April 2014
Junior Member
Ok, thank you very much.
Re: Escape file name [message #1422470 is a reply to message #1421347] Fri, 12 September 2014 22:40 Go to previous message
Robin Rosenberg is currently offline Robin RosenbergFriend
Messages: 332
Registered: July 2009
Senior Member
Christian Halstrick skrev 2014-09-11 10.41:
> No chance. Open Windows Notepad, type in a text and select "File->Save As..." and enter "name:a:b:c.txt". Notepad will return an error. On windows those filenames are
> disallowed. And there is no feature that I know of that you can tell git/jgit to write a file named "name:a:b:c.txt" into a file with different name.
>

Try a name with just one colon and notepad will happily save a file, but it will not do what most people expect. Only malware writers use this Windows feature called ADS
(Alternative Data Streams). Because name:a.txt will not be saved as a file of that name we ban it as a security measure.

One could conceive some name mangling, but I don't think JGit should lead the way here. Just tell the guilty ones to rename the files properly or do it yourself.

git mv --cached bad-name good-name should work for these files

-- robin
Previous Topic:unchanged files are being marked as changed
Next Topic:Checking out commit
Goto Forum:
  


Current Time: Tue Nov 19 22:51:56 GMT 2019

Powered by FUDForum. Page generated in 0.01915 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top