www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Importing text file, path not found

reply "Tolga Cakiroglu (tcak)" <tcak pcak.com> writes:
I am testing with the import expression. I am using the "-J" flag 
while compiling.

dmd app.d -J/home/user/include


void main(){
	auto test = json.parseJSON( 
import("/home/user/include/test.json") );
}


1. Because I am giving the full path of that file to be imported. 
But compiler is complaining about that it cannot find the file. 
If I remove the path, and leave the file name only, it works. Am 
I doing something wrong, or bug?

2. Why do I need to tell compiler where to look at if I am going 
to tell where the file is already? Shouldn't it be like "Hey 
compiler, if you cannot while the file, look at those places", 
and I shouldn't need to use J flag if not necessary?
Feb 18 2014
next sibling parent reply "Tolga Cakiroglu (tcak)" <tcak pcak.com> writes:
On Tuesday, 18 February 2014 at 08:45:16 UTC, Tolga Cakiroglu 
(tcak) wrote:
 I am testing with the import expression. I am using the "-J" 
 flag while compiling.

 dmd app.d -J/home/user/include


 void main(){
 	auto test = json.parseJSON( 
 import("/home/user/include/test.json") );
 }


 1. Because I am giving the full path of that file to be 
 imported. But compiler is complaining about that it cannot find 
 the file. If I remove the path, and leave the file name only, 
 it works. Am I doing something wrong, or bug?

 2. Why do I need to tell compiler where to look at if I am 
 going to tell where the file is already? Shouldn't it be like 
 "Hey compiler, if you cannot while the file, look at those 
 places", and I shouldn't need to use J flag if not necessary?
- Grammar issues - 1. Because I am giving the full path of that file to be imported, compiler is complaining about that it cannot find the file. If I remove the path, and leave the file name only, it works. Am I doing something wrong, or bug? 2. Why do I need to tell compiler where to look at if I am going to tell where the file is already? Shouldn't it be like "Hey compiler, if you cannot find the file, look at those places", and I shouldn't need to use J flag if not necessary?
Feb 18 2014
parent "bearophile" <bearophileHUGS lycos.com> writes:
Tolga Cakiroglu (tcak):

 1. Because I am giving the full path of that file to be
 imported, compiler is complaining about that it cannot find
 the file. If I remove the path, and leave the file name only,
 it works. Am I doing something wrong, or bug?

 2. Why do I need to tell compiler where to look at if I am
 going to tell where the file is already? Shouldn't it be like
 "Hey compiler, if you cannot find the file, look at those
 places", and I shouldn't need to use J flag if not necessary?
It seems things are working as designed. The J flag is meant for security. Bye, bearophile
Feb 18 2014
prev sibling parent reply "Dicebot" <public dicebot.lv> writes:
On Tuesday, 18 February 2014 at 08:45:16 UTC, Tolga Cakiroglu 
(tcak) wrote:
 1. Because I am giving the full path of that file to be 
 imported. But compiler is complaining about that it cannot find 
 the file. If I remove the path, and leave the file name only, 
 it works. Am I doing something wrong, or bug?

 2. Why do I need to tell compiler where to look at if I am 
 going to tell where the file is already? Shouldn't it be like 
 "Hey compiler, if you cannot while the file, look at those 
 places", and I shouldn't need to use J flag if not necessary?
It is a matter of security I think. By restricting imports to only explicitly allowed locations and prohibiting fully-qualified paths dmd guarantees you that compiled program won't access anything outside of that sandbox. That way compilation process stays relatively safe.
Feb 18 2014
parent reply "Tolga Cakiroglu" <tcak pcak.com> writes:
On Tuesday, 18 February 2014 at 09:24:50 UTC, Dicebot wrote:
 On Tuesday, 18 February 2014 at 08:45:16 UTC, Tolga Cakiroglu 
 (tcak) wrote:
 1. Because I am giving the full path of that file to be 
 imported. But compiler is complaining about that it cannot 
 find the file. If I remove the path, and leave the file name 
 only, it works. Am I doing something wrong, or bug?

 2. Why do I need to tell compiler where to look at if I am 
 going to tell where the file is already? Shouldn't it be like 
 "Hey compiler, if you cannot while the file, look at those 
 places", and I shouldn't need to use J flag if not necessary?
It is a matter of security I think. By restricting imports to only explicitly allowed locations and prohibiting fully-qualified paths dmd guarantees you that compiled program won't access anything outside of that sandbox. That way compilation process stays relatively safe.
Hmm. Should I understand the sandbox as if I am going to be compiling someone else's code, only looking at -J flags will be enough to make sure it is not using any of my private files?
Feb 18 2014
parent "Dicebot" <public dicebot.lv> writes:
On Tuesday, 18 February 2014 at 10:10:14 UTC, Tolga Cakiroglu 
wrote:
 Hmm. Should I understand the sandbox as if I am going to be 
 compiling someone else's code, only looking at -J flags will be 
 enough to make sure it is not using any of my private files?
It is the intention. I can't guarantee there are no bugs that break that assumption though :)
Feb 18 2014