0

I'm currently working an a rather large web project which is written using C servlets ( utilizing GWAN Web server ). In the past I've used a couple of IDEs for my LAMP/PHP jobs, like Eclipse.

My problems with Eclipse are that you can either mirror the project locally, which isn't possible in this case as I'm working on a Mac (server does not run on OSX), or use the "remote" view, which would re-upload files when you save them.

In the later case, the file is only partly written while uploading, which makes this a no-go for a running web server, or the file could become corrupted if the connection was lost during uploading. Also, for changing some character, uploading the whole file seems rather inefficient to me.


So I was thinking:

Wouldn't it be possible to have the IDE open Vim per SSH and mirror my changes there, and then just :w (save) ? Or use some kind of diff-files for changes?

The first one would be preffered, as it has the added advantage of Vim .swp files, which makes it possible that others know when someone is already editing the file.


My current solution is using ssh+vim, but then I lose all the cool features I have with Eclipse and other more advanced IDEs.

Also, regarding X-Forwarding: The reason I don't like it is speed. It feels way slower than just editing locally, and takes up unneeded bandwidth, when all I want to do is basically "text editing".

P.S.: I couldn't find any more appropriate tags for the question, especially no "remote" tag, but if you know any, feel free to add them. Also, if there is another similar question, feel free to point it out - I couldn't find any.

Thank you very much.

griffin
  • 1,261
  • 8
  • 24
  • Anything in http://vim.wikia.com/wiki/Editing_remote_files_via_scp_in_vim matches your need? – Fredrik Pihl Sep 27 '13 at 18:35
  • @FredrikPihl no sorry, that's using vim again, and scp as well, which means uploading the whole file again. Both things I want to avoid. But thanks for the link. – griffin Sep 27 '13 at 18:37
  • Have a local copy of the sources, edit locally (probably using Eclipse), build locally until all looks good, upload the modified files, build on the remote host, test on the remote host, patch on the remote host, download the patched files and start over. – alk Sep 27 '13 at 18:41
  • I can't "build locally" ( "mirror the project locally, which isn't possible in this case as I'm working on a Mac (server does not run on OSX)" ), and also, this again has the problem of partial files while uploading. Of course, I could upload to a different directory and move them on the server then, but for web developement, where you normally edit just a bit (a line, correct a typo etc) and then press reload in the browser, this is/would be a huge hassle - the reason why I'm currently using Vim directly on the server (and the reason for this question) – griffin Sep 27 '13 at 18:46
  • Ok, I understood you were referring to C coded "servlets". Btw, just out of curiosity: You are editing on a live-system? *shudder* – alk Sep 27 '13 at 19:01
  • So what about mounting the server's file system via NFS, Samba or such to your local machine? – alk Sep 27 '13 at 19:04
  • @alk No, the project isn't live yet, but I'm editing while the server is running, and the C "servlets" get recompiled automatically after a change, so I only need to reload in my browser to see changes. But I've done so in the past under rare certain circumstances (test installation temporarily offline and a bug needs fixing asap for example). Regarding mounting: Besides this project, I work on random servers from time to time, so I'd prefer a solution which doesn't need any initial setup, and also I don't like adding services or opening new ports, even if IP restricted. – griffin Sep 27 '13 at 19:12

2 Answers2

2

If you're concerned about having to transmit the entire file for minor changes, the only solution that comes to my mind is running (either continuously, or on demand) an rsync job that mirrors the remote site to your local system (and back). The rsync protocol just transmits the delta information. According to Are rsync operations atomic at file level?, the change is atomic.

Community
  • 1
  • 1
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Actually a very interesting idea! Do you know of a way to use this with an IDE (Eclipse would be cool) and make it run on demand? I think it could be done with ANT scripting or the like, but unfortunately I don't know enough about Eclipse + ANT to build a nice integration there, so I would not have to edit the script every time for a new server/different path ... Also, a more local-caching like approach would be nice, so I don't flood my disk with source files over time, but that's more of an added bonus if it is possible I guess ;) – griffin Sep 27 '13 at 19:18
  • @griffin: `rsync` was exactly what I had in mind when I commented: "*... upload ... download ...*" on the OP. – alk Sep 27 '13 at 19:20
  • @alk sorry, I can't read your mind :/ And I know rsync, just didn't think about using it in this way / for this problem. My question/comment still stands though, as this is "only" a first piece of the puzzle I guess ;) – griffin Sep 27 '13 at 19:22
  • With Vim, you could trigger on the `BufWritePost` event, but I would probably just run this continuously in a loop, from a little shell script that configures the paths to sync. – Ingo Karkat Sep 27 '13 at 19:23
  • That would mean having a script for each server / path I work on right? Also, a loop would probably have to run every second or so, as that's about the time it takes me to cmd+tab & cmd+r to switch to browser and reload :/ (btw upvoted your answer for now, trying to think of a complete rsync based solution right now, but I'm still far off unfortunately :( ) – griffin Sep 27 '13 at 19:28
  • The more directories the job has to cover, the longer it'll take. Is there an _inotify_ API on Mac OS?! With it, you could be informed about any local file changes, and only selectively push those back to the server. – Ingo Karkat Sep 27 '13 at 19:30
  • There's kqueue, which is more or less the equivalent, and it can be used with launchd if I remember correctly, so relatively simple actually. But I just found an eclipse rsync plugin which looks interesting, gonna take a try at it and if it fulfills my reqs I'll accept this answer for pointing me in the right direction ;) – griffin Sep 27 '13 at 19:32
1

Another possibility: run everything in a virtual machine on your Mac. The server and the IDE/text editor are both on the same virtual machine so you don't have to fear network issues.

Because the source code on the virtual machine is under some kind of VCS the classic code → test → commit process is trivial (at least theoretically).

romainl
  • 186,200
  • 21
  • 280
  • 313
  • A nice idea, but the question was more meant to be a general one, as I'm normally working on many other servers as well, though with a LAMP/PHP setup there. Also, a local vm is not as well suited for developing in teams / with more people. But still, upvote for thinking "outside of the box" (at least for this question your answer is) ;) – griffin Sep 27 '13 at 21:07
  • More like "thinking inside the virtual box" ;-) – romainl Sep 28 '13 at 06:05