aboutsummaryrefslogtreecommitdiff
path: root/src/library_fs.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/library_fs.js')
-rw-r--r--src/library_fs.js39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/library_fs.js b/src/library_fs.js
index 8ea6b06f..e1397356 100644
--- a/src/library_fs.js
+++ b/src/library_fs.js
@@ -18,7 +18,7 @@ mergeInto(LibraryManager.library, {
devices: [null],
streams: [null],
nextInode: 1,
- name_table: new Array(4096),
+ name_table: null,
currentPath: '/',
initialized: false,
// Whether we are currently ignoring permissions. Useful when preparing the
@@ -27,16 +27,21 @@ mergeInto(LibraryManager.library, {
// to modify the filesystem freely before run() is called.
ignorePermissions: true,
- ErrnoError: function(errno) {
- this.errno = errno;
- for (var key in ERRNO_CODES) {
- if (ERRNO_CODES[key] === errno) {
- this.code = key;
- break;
+ ErrnoError: (function() {
+ function ErrnoError(errno) {
+ this.errno = errno;
+ for (var key in ERRNO_CODES) {
+ if (ERRNO_CODES[key] === errno) {
+ this.code = key;
+ break;
+ }
}
- }
- this.message = ERRNO_MESSAGES[errno] + ' : ' + new Error().stack;
- },
+ this.message = ERRNO_MESSAGES[errno];
+ };
+ ErrnoError.prototype = new Error();
+ ErrnoError.prototype.constructor = ErrnoError;
+ return ErrnoError;
+ }()),
handleFSError: function(e) {
if (!(e instanceof FS.ErrnoError)) throw e + ' : ' + new Error().stack;
@@ -504,7 +509,7 @@ mergeInto(LibraryManager.library, {
var mode = FS.getMode(canRead, canWrite);
return FS.create(path, mode);
},
- createDataFile: function(parent, name, data, canRead, canWrite) {
+ createDataFile: function(parent, name, data, canRead, canWrite, canOwn) {
var path = PATH.join(typeof parent === 'string' ? parent : FS.getPath(parent), name);
var mode = FS.getMode(canRead, canWrite);
var node = FS.create(path, mode);
@@ -517,7 +522,7 @@ mergeInto(LibraryManager.library, {
// make sure we can write to the file
FS.chmod(path, mode | {{{ cDefine('S_IWUGO') }}});
var stream = FS.open(path, 'w');
- FS.write(stream, data, 0, data.length, 0);
+ FS.write(stream, data, 0, data.length, 0, canOwn);
FS.close(stream);
FS.chmod(path, mode);
}
@@ -761,7 +766,7 @@ mergeInto(LibraryManager.library, {
// You can also call this with a typed array instead of a url. It will then
// do preloading for the Image/Audio part, as if the typed array were the
// result of an XHR that you did manually.
- createPreloadedFile: function(parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile) {
+ createPreloadedFile: function(parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn) {
Browser.init();
// TODO we should allow people to just pass in a complete filename instead
// of parent and name being that we just join them anyways
@@ -769,7 +774,7 @@ mergeInto(LibraryManager.library, {
function processData(byteArray) {
function finish(byteArray) {
if (!dontCreateFile) {
- FS.createDataFile(parent, name, byteArray, canRead, canWrite);
+ FS.createDataFile(parent, name, byteArray, canRead, canWrite, canOwn);
}
if (onload) onload();
removeRunDependency('cp ' + fullname);
@@ -863,6 +868,8 @@ mergeInto(LibraryManager.library, {
assert(stderr.fd === 3, 'invalid handle for stderr (' + stderr.fd + ')');
},
staticInit: function() {
+ FS.name_table = new Array(4096);
+
FS.root = FS.createNode(null, '/', {{{ cDefine('S_IFDIR') }}} | 0777, 0);
FS.mount(MEMFS, {}, '/');
@@ -1316,7 +1323,7 @@ mergeInto(LibraryManager.library, {
if (!seeking) stream.position += bytesRead;
return bytesRead;
},
- write: function(stream, buffer, offset, length, position) {
+ write: function(stream, buffer, offset, length, position, canOwn) {
if (length < 0 || position < 0) {
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
}
@@ -1340,7 +1347,7 @@ mergeInto(LibraryManager.library, {
// seek to the end before writing in append mode
FS.llseek(stream, 0, {{{ cDefine('SEEK_END') }}});
}
- var bytesWritten = stream.stream_ops.write(stream, buffer, offset, length, position);
+ var bytesWritten = stream.stream_ops.write(stream, buffer, offset, length, position, canOwn);
if (!seeking) stream.position += bytesWritten;
return bytesWritten;
},