Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Checking whether workspace is in use(/.metadata/.lock no longer works)
Checking whether workspace is in use [message #541760] Tue, 22 June 2010 08:55 Go to next message
Rodrigo Hjort is currently offline Rodrigo Hjort
Messages: 2
Registered: June 2010
Junior Member
In a shell script in Linux I need to check whether a given workspace directory is in use by an open Eclipse instance.

In order to perform that, I used to look for this zeroed file: WORKSPACE/.metadata/.lock

However, it seems the current Eclipse 3.5 checking is no longer based on that file, as the latter remains stored in the directory even after closing the IDE.

So, how that workspace checking is made currently?

Thanks in advance.

Regards,

Rodrigo Hjort
http://agajorte.blogspot.com
Re: Checking whether workspace is in use [message #541807 is a reply to message #541760] Tue, 22 June 2010 11:08 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25924
Registered: July 2009
Senior Member
Rodrigo,

I think that's still being used. Perhaps a crashed Eclipse left one
behind. Perhaps you should check by attempting to open an output stream
to the file, which should result in a failure because it is "in use" by
Eclipse.


Rodrigo Hjort wrote:
> In a shell script in Linux I need to check whether a given workspace
> directory is in use by an open Eclipse instance.
>
> In order to perform that, I used to look for this zeroed file:
> WORKSPACE/.metadata/.lock
>
> However, it seems the current Eclipse 3.5 checking is no longer based
> on that file, as the latter remains stored in the directory even after
> closing the IDE.
>
> So, how that workspace checking is made currently?
>
> Thanks in advance.
>
> Regards,
>
> Rodrigo Hjort
> http://agajorte.blogspot.com
Re: Checking whether workspace is in use [message #541843 is a reply to message #541807] Tue, 22 June 2010 13:32 Go to previous messageGo to next message
Rodrigo Hjort is currently offline Rodrigo Hjort
Messages: 2
Registered: June 2010
Junior Member
Ed,

Eclipse 3.5 definitely seems to ignore .lock file.

Firstly, I started the IDE switching to a brand new worskpace. Then, there was the 0-bytes .lock file. But strangely it remains in .metadata directory after closing Eclipse.

/tmp/ws/.metadata$ ls -la
total 76
drwxr-xr-x 4 user group 4096 2010-06-22 14:00 .
drwxr-xr-x 4 user group 4096 2010-06-22 14:00 ..
-rw-r--r-- 1 user group 0 2010-06-22 14:00 .lock
-rw-r--r-- 1 user group 49973 2010-06-22 14:01 .log
drwxr-xr-x 3 user group 4096 2010-06-22 14:00 .mylyn
drwxr-xr-x 57 user group 4096 2010-06-22 14:00 .plugins
-rw-r--r-- 1 user group 26 2010-06-22 14:01 version.ini

Secondly, I tried to create another .lock file with an output stream (ls > .lock) as you suggested. I opened Eclipse and no error of workspace in use was raised.

Here are the version specifications:

Eclipse SDK
Version: 3.5.2
Build id: M20100211-1343


Any other suggestion?
Re: Checking whether workspace is in use [message #541867 is a reply to message #541843] Tue, 22 June 2010 15:51 Go to previous message
David Wegener is currently offline David Wegener
Messages: 1334
Registered: July 2009
Senior Member
"Rodrigo Hjort" <rodrigo_hjort@yahoo.com> wrote in message
news:hvqs3g$t0o$1@build.eclipse.org...
> Ed,
>
> Eclipse 3.5 definitely seems to ignore .lock file.
>
> Firstly, I started the IDE switching to a brand new worskpace. Then, there
> was the 0-bytes .lock file. But strangely it remains in .metadata
> directory after closing Eclipse.
>
> /tmp/ws/.metadata$ ls -la
> total 76
> drwxr-xr-x 4 user group 4096 2010-06-22 14:00 .
> drwxr-xr-x 4 user group 4096 2010-06-22 14:00 ..
> -rw-r--r-- 1 user group 0 2010-06-22 14:00 .lock
> -rw-r--r-- 1 user group 49973 2010-06-22 14:01 .log
> drwxr-xr-x 3 user group 4096 2010-06-22 14:00 .mylyn
> drwxr-xr-x 57 user group 4096 2010-06-22 14:00 .plugins
> -rw-r--r-- 1 user group 26 2010-06-22 14:01 version.ini
>
> Secondly, I tried to create another .lock file with an output stream (ls >
> .lock) as you suggested. I opened Eclipse and no error of workspace in use
> was raised.
>
> Here are the version specifications:
>
> Eclipse SDK
> Version: 3.5.2
> Build id: M20100211-1343
>
> Any other suggestion?

Eclipse workspace locking has become much more sophisticated over the years.
Simply checking for the existence of a .lock file would prevent Eclipse from
starting after a crash. Now Eclipse uses the java nio file locking
mechanism to lock the file. The file locks are release if the process
crashs so subsquent attempts to start Eclipse will be successful. However,
if you try to lock the file while Eclipse has the lock intact, it will fail.

You should be able to use a similar technique to check to see if Eclipse has
the workspace directory open.
Previous Topic:Export eclipse installation
Next Topic:Problem with package structure
Goto Forum:
  


Current Time: Mon Jul 28 06:33:40 EDT 2014

Powered by FUDForum. Page generated in 0.02352 seconds