Your question seems a bit illogical, I mean, in order for the whole
thing to work you'd have to make sure that you run the program like
this:
cd /path/to/symlink
./script.js
The following would fail:
/path/to/symlink/script.js
Why don't you better detect the timestamp of script.js, rather than
that of the directory it runs from?
Cheers,
--
Mihai Bazon,
http://mihai.bazon.net/blog
[...] dirs in different environments, so I didn't have to hard-code where
the "timestamp" file was). [...]
Just in case:
setTimeout(function(){if (problemSolved) console.log('Thanks
Mihai');}, 3600);
--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
PWD=pwned node -e 'process.env.PWD' // does this output the
current working dir?
Even in shell scripts, "$PWD" is not as good as "$(pwd)" for this
reason. Do not rely on it.
If you want the real path when running in a directory path that
contains symlinks, use:
var fs = require('fs')
fs.realpath(p, function (er, real) { ... })
// or
var real = fs.realpathSync(p) // throws on error
If you want to know the dir that a script lives in, check the
__dirname free variable. It should already be realpathed.
var scriptLivesInThisDir = __dirname
To get the real path of the cwd, you could do:
fs.realpath(process.cwd(), function (er, real) { ... })
// or
var real = fs.realpathSync(process.cwd())
There is no way in your script to detect if it was loaded via a
symlink. It always behaves as if it was loaded from its actual real
file location.
To find a file that exists in the same folder as your script, you can
use path.resolve() against the __dirname.
var tsFile = path.resolve(__dirname, '.timestamp')
To find it in the cwd, you can do:
var ts = path.resolve(process.cwd(), '.timestamp')
To find it in the real path of the cwd, you can do:
var ts = path.resolve(fs.realpathSync(process.cwd()), '.timestamp')
// or, equivalently:
var ts = fs.realpathSync(path.resolve(process.cwd(), '.timestamp'))
Does that answer your question(s)?
--i
--i
Why do you need to know the non-realpath'ed location of your js file?
process.env.PWD won't tell you this anyway. Incidentally, I wasn't
being clever enough when I said you couldn't get it. If you want to
know the non-realpath'ed location of the *main* script, you can look
at process.argv[1]. (Of course, if you're not in the main script,
then that doesn't help you much.)
What is the problem you're trying to solve, exactly? I read through
the previous emails, and didn't see anything that required that.
--i
If I understand your use case, couldn't you just check if the realpath
of the live symlink is the same as the realpath of the currently
running code?
if ( fs.realpathSync ( __dirname + '/../live' ) !==
fs.realpathSync ( __dirname ))
gracefulExit ()
–Jacob
if (fs.realpathSync(liveLocation).indexOf(__dirname) === 0) {
// it is live
} else {
gracefulExit()
}
--i