diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-08-05 14:00:16 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-08-05 14:00:16 -0700 |
commit | 1b7122c6aaa19cb6e2a62598dca8e0fd9e3cc7a7 (patch) | |
tree | 659d33c0fcfa4f6ae3afaae9808649e4021979b7 /tools/file_packager.py | |
parent | 6039aea9a13ea217301c2c19eca3e857dc2dace7 (diff) | |
parent | a0c6ab57cb11258df23dd670aebdc260d9e16da3 (diff) |
Merge branch 'incoming'
Diffstat (limited to 'tools/file_packager.py')
-rw-r--r-- | tools/file_packager.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/tools/file_packager.py b/tools/file_packager.py index 575e5957..136da609 100644 --- a/tools/file_packager.py +++ b/tools/file_packager.py @@ -122,8 +122,6 @@ for arg in sys.argv[1:]: srcpath, dstpath = arg.split('@') # User is specifying destination filename explicitly. else: srcpath = dstpath = arg # Use source path as destination path. - if os.path.isabs(dstpath): - print >> sys.stderr, 'Warning: Embedding an absolute file/directory name "' + dstpath + '" to the virtual filesystem. The file will be made available in the path "' + dstpath + '", and not in the root of the generated file system. Use the explicit syntax --preload-file srcpath@dstpath to specify the target location the absolute source path should be directed to.' if os.path.isfile(srcpath) or os.path.isdir(srcpath): data_files.append({ 'srcpath': srcpath, 'dstpath': dstpath, 'mode': mode }) else: @@ -198,6 +196,22 @@ for file_ in data_files: os.path.walk(file_['srcpath'], add, [file_['mode'], file_['srcpath'], file_['dstpath']]) data_files = filter(lambda file_: not os.path.isdir(file_['srcpath']), data_files) +# Absolutize paths, and check that they make sense +curr_abspath = os.path.abspath(os.getcwd()) +for file_ in data_files: + if file_['srcpath'] == file_['dstpath']: + # This file was not defined with src@dst, so we inferred the destination from the source. In that case, + # we require that the destination not be under the current location + path = file_['dstpath'] + abspath = os.path.abspath(path) + if DEBUG: print >> sys.stderr, path, abspath, curr_abspath + if not abspath.startswith(curr_abspath): + print >> sys.stderr, 'Error: Embedding "%s" which is below the current directory. This is invalid since the current directory becomes the root that the generated code will see' % path + sys.exit(1) + file_['dstpath'] = abspath[len(curr_abspath)+1:] + if os.path.isabs(path): + print >> sys.stderr, 'Warning: Embedding an absolute file/directory name "' + path + '" to the virtual filesystem. The file will be made available in the relative path "' + file_['dstpath'] + '". You can use the explicit syntax --preload-file srcpath@dstpath to explicitly specify the target location the absolute source path should be directed to.' + for file_ in data_files: file_['dstpath'] = file_['dstpath'].replace(os.path.sep, '/') # name in the filesystem, native and emulated if file_['dstpath'].endswith('/'): # If user has submitted a directory name as the destination but omitted the destination filename, use the filename from source file |