refactored open()
This commit is contained in:
parent
d8b225efbe
commit
25342d5876
79
src/fs.js
79
src/fs.js
|
@ -818,48 +818,41 @@ define(function(require) {
|
||||||
FileSystem.prototype._release_descriptor = function _release_descriptor(fd) {
|
FileSystem.prototype._release_descriptor = function _release_descriptor(fd) {
|
||||||
delete this.openFiles[fd];
|
delete this.openFiles[fd];
|
||||||
};
|
};
|
||||||
FileSystem.prototype._open = function _open(path, flags, callback) {
|
FileSystem.prototype._open = function _open(context, path, flags, callback) {
|
||||||
var that = this;
|
var that = this;
|
||||||
this.promise.then(
|
var deferred = when.defer();
|
||||||
function() {
|
// var transaction = that.db.transaction([FILE_STORE_NAME], IDB_RW);
|
||||||
var deferred = when.defer();
|
// var files = transaction.objectStore(FILE_STORE_NAME);
|
||||||
var transaction = that.db.transaction([FILE_STORE_NAME], IDB_RW);
|
|
||||||
var files = transaction.objectStore(FILE_STORE_NAME);
|
|
||||||
|
|
||||||
function check_result(error, fileNode) {
|
function check_result(error, fileNode) {
|
||||||
if(error) {
|
if(error) {
|
||||||
// if(transaction.error) transaction.abort();
|
// if(transaction.error) transaction.abort();
|
||||||
deferred.reject(error);
|
deferred.reject(error);
|
||||||
} else {
|
} else {
|
||||||
var position;
|
var position;
|
||||||
if(_(flags).contains(O_APPEND)) {
|
if(_(flags).contains(O_APPEND)) {
|
||||||
position = fileNode.size;
|
position = fileNode.size;
|
||||||
} else {
|
} else {
|
||||||
position = 0;
|
position = 0;
|
||||||
}
|
|
||||||
var openFileDescription = new OpenFileDescription(fileNode.id, flags, position);
|
|
||||||
var fd = that._allocate_descriptor(openFileDescription);
|
|
||||||
deferred.resolve(fd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
var openFileDescription = new OpenFileDescription(fileNode.id, flags, position);
|
||||||
|
var fd = that._allocate_descriptor(openFileDescription);
|
||||||
|
deferred.resolve(fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
flags = validate_flags(flags);
|
flags = validate_flags(flags);
|
||||||
if(!flags) {
|
if(!flags) {
|
||||||
deferred.reject(new EInvalid('flags is not valid'));
|
deferred.reject(new EInvalid('flags is not valid'));
|
||||||
}
|
}
|
||||||
|
|
||||||
open_file(that, files, path, flags, check_result);
|
open_file(that, context, path, flags, check_result);
|
||||||
deferred.promise.then(
|
deferred.promise.then(
|
||||||
function(result) {
|
function(result) {
|
||||||
callback(undefined, result);
|
callback(undefined, result);
|
||||||
},
|
|
||||||
function(error) {
|
|
||||||
callback(error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
function() {
|
function(error) {
|
||||||
callback(new EFileSystemError('unknown error'));
|
callback(error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1547,7 +1540,17 @@ define(function(require) {
|
||||||
IndexedDBFileSystem.prototype = new FileSystem();
|
IndexedDBFileSystem.prototype = new FileSystem();
|
||||||
IndexedDBFileSystem.prototype.constructor = IndexedDBFileSystem;
|
IndexedDBFileSystem.prototype.constructor = IndexedDBFileSystem;
|
||||||
IndexedDBFileSystem.prototype.open = function open(path, flags, callback) {
|
IndexedDBFileSystem.prototype.open = function open(path, flags, callback) {
|
||||||
this._open(path, flags, callback);
|
var fs = this;
|
||||||
|
this.promise.then(
|
||||||
|
function() {
|
||||||
|
var transaction = fs.db.transaction([FILE_STORE_NAME], IDB_RW);
|
||||||
|
var files = transaction.objectStore(FILE_STORE_NAME);
|
||||||
|
fs._open(files, path, flags, callback);
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
callback(new EFileSystemError('unknown error'));
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
IndexedDBFileSystem.prototype.close = function close(fd, callback) {
|
IndexedDBFileSystem.prototype.close = function close(fd, callback) {
|
||||||
this._close(fd, callback);
|
this._close(fd, callback);
|
||||||
|
@ -1592,8 +1595,8 @@ define(function(require) {
|
||||||
this._rename(oldpath, newpath, callback);
|
this._rename(oldpath, newpath, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: this needs implementation
|
||||||
function WebSQLFileSystem(name, flags) {
|
function WebSQLFileSystem(name, flags) {
|
||||||
// FIXME: NOT IMPLEMENTED
|
|
||||||
}
|
}
|
||||||
WebSQLFileSystem.prototype = new FileSystem();
|
WebSQLFileSystem.prototype = new FileSystem();
|
||||||
IndexedDBFileSystem.prototype.constructor = WebSQLFileSystem;
|
IndexedDBFileSystem.prototype.constructor = WebSQLFileSystem;
|
||||||
|
|
Loading…
Reference in New Issue