[gnome-weather/wip/new-package-js: 12/14] package: recognize if the application launched is a symlink



commit 7c9a34edd8b5871faec12f3ceb321b6a864f5ae6
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sat Feb 8 19:46:46 2014 +0100

    package: recognize if the application launched is a symlink
    
    And if so, resolve the symlink before using the application name.

 src/package.js |   29 +++++++++++++++++++++--------
 1 files changed, 21 insertions(+), 8 deletions(-)
---
diff --git a/src/package.js b/src/package.js
index 472c6bc..871fdfc 100644
--- a/src/package.js
+++ b/src/package.js
@@ -43,12 +43,22 @@ var localedir;
 
 /*< private >*/
 let _base;
+let _programInvocationName;
+
+function _resolveProgramInvocationName() {
+    let file = Gio.File.new_for_path(System.programInvocationName);
+    let info = file.query_info('standard::is-symlink,standard::symlink-target',
+                               Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
+                               null);
+    if (info.get_is_symlink())
+        _programInvocationName = info.get_symlink_target();
+    else
+        _programInvocationName = file.get_path();
+}
 
 function _runningFromSource() {
-    let fileName = System.programInvocationName;
-    let prgName = GLib.path_get_basename(fileName);
-
-    let binary = Gio.File.new_for_path(fileName);
+    let prgName = GLib.path_get_basename(_programInvocationName);
+    let binary = Gio.File.new_for_path(_programInvocationName);
     let sourceBinary = Gio.File.new_for_path('./src/' + prgName);
     return binary.equal(sourceBinary);
 }
@@ -58,7 +68,7 @@ function _makeNamePath(name) {
 }
 
 function _guessPrefixAndLibdir() {
-    let application = Gio.File.new_for_path(System.programInvocationName);
+    let application = Gio.File.new_for_path(_programInvocationName);
     let pkglibdir = application.get_parent();
     libdir = pkglibdir.get_parent().get_path();
     prefix = pkglibdir.get_parent().get_parent().get_path();
@@ -111,9 +121,12 @@ function _guessPrefixAndLibdir() {
  * As a side effect, init() calls GLib.set_prgname().
  */
 function init(params) {
-    params = params || {};
     window.pkg = imports.package;
-    name = GLib.path_get_basename(System.programInvocationName);
+
+    _resolveProgramInvocationName();
+
+    params = params || {};
+    name = GLib.path_get_basename(_programInvocationName);
     version = params.version || '';
 
     // Must call it first, because it can only be called
@@ -183,7 +196,7 @@ function init(params) {
 function start(params) {
     init(params);
 
-    return imports.main.main([System.programInvocationName].concat(ARGV));
+    return imports.main.main([_programInvocationName].concat(ARGV));
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]