Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"java.io.FileNotFoundException" on synchronization #15

Open
thorstenkampe opened this issue Jan 31, 2015 · 3 comments
Open

"java.io.FileNotFoundException" on synchronization #15

thorstenkampe opened this issue Jan 31, 2015 · 3 comments

Comments

@thorstenkampe
Copy link

PyCharm 4.0.4 on Windows:
I have one Project called default. The project's location is F:\Program Files\PyCharm\.PyCharm\PycharmProjects\default. This project has multiple content roots. Trying to sync F:\Documents\dev\python\script\script.py results in

Sync warning: java.io.FileNotFoundException: F:\Program Files\PyCharm\.PyCharm\PycharmProjects\default\F:\Documents\dev\python\script\script.py (Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch)

Obviously Source Synchronizer "thinks" the location of the file to be synchronized is relative to the project root.

@Buccaneersdan
Copy link

I think I've found the cause for this bug. I fixed it for SFTPFileSynchronizer.
I've put

if (dirsToCreate != null &&
    dirsToCreate.length != 0 &&
    dirsToCreate[0] != null &&
    dirsToCreate[0].trim().length() != 0) {

in line 128 in SFTPFileSynchronizer.java (before the comment).

Currently the error happens like this in pycharm:
In sourcesync config set the Root Path to e.g. "/home"
Create a python file in the root folder of the project.
When uploading the error happens in line 136, when channelSftp.cd(dirToCreate); tries to change to the directory "".
The directory is empty because dirsToCreate probably contains one array-element with an empty string.

I've cloned it and imported it into intellij, and successfully build a modified version of the plugin.

I fixed FTPFileSynchronizer.java, FTPSFileSynchronizer.java and SFTPFileSynchronizer.java.
Didn't touch SCPFileSynchronizer.java.

Should I collaborate on the project (for this small changes it isn't nessecary I guess).
If yes: Do I have to fork the project and issue a pull request? I did not collaborate on a project until now.

The modified plugin build: sourcesync.zip (You have to unzip it before using "Install plugin from disk" to the jar in pycharm).

@fioan89
Copy link
Owner

fioan89 commented Mar 16, 2017

Hi @JackLeEmmerdeur, thx for the update. Would be fair to you if you would do a fork and push a merge request. But before doing that, this fix needs to discussed at length. Your fix might work but I don't think it's the proper place. Historically speaking - the first few versions of the plugin tried to upload the file to a remote path that would contain the project name. For example if you have a project called testproject and java file residing in: C:\MyProjects\testproject\src\java\com\example\ToSyncFile.java. Then the first versions of sourcesync tried to import the ToSyncFile in root + \testproject + \src\java\com\example\ToSyncFile.java

In the meantime \testproject was removed from the logic and you will have to add it manually to root if you want. But I think that change was unfinished, in the sense that the local path is still computed to the path of the project, which is kind of stupid (in my defense at the time I wrote the code I did not knew that Intellij/PyCharm supports project configuration in a different place than the source of files)

In another words - unfinished fix + projects configurations in different location than the src directory can get you in this sort of situations. So in my opinion the fix should be done in the action package by not computing the path of source file relative to the project. What do you think?

@Buccaneersdan
Copy link

Buccaneersdan commented Mar 23, 2017

Hi @fioan89.
Hadn't had much time, but after a little while of considering your mentioned different approach, I managed to implement both issues:

  1. Issuers problem: Selected file at root of projectdir *(1)
  2. Your supposedly related problem: Selected file in external content source directory *(2)

Both problems are fixed within action/ActionSelectedFilesToRemote.java as you suggested.
Total LOC for the ActionSelectedFilesToRemote.java is about 30 lines.
I didn't touch e.g. synchronizer/SFTPFileSynchronizer.java.
I needed to add a litte (8 lines) recursive helper method, taken from a stackoverflow-thread (url in method-comment) to api/Utils.java

(*1) File at project root

Project dir: F:\Documents\dev\python\script
File to sync: F:\Documents\dev\python\script\script.py
Remote file: /script.py.

(*2) External content-root-dir

  1. Example (Same base path)
    Project dir: F:\Documents\dev\java\myproject
    File to sync: F:\Documents\dev\java\somelib\resources\test.json
    Remote file: /somelib/resources/test.json

  2. Example (Different base path)
    Project dir: F:\Documents\dev\java\myproject
    File to sync: F:\Downloads\java\libs\worksforme\src\robot.java
    Remote file: /Downloads/java/libs/worksforme/src/robot.java

I can do a push from my fork if you like. ATM I just cloned your repo locally. I haven't pushed code to an original repo on github in the past and never did a pull request either, but I speak a little bit of GIT, as using it on work. Maybe you could explain your usual way of importing/reviewing code from contributors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants