refactored open()

This commit is contained in:
Alan Kligman 2013-11-21 00:36:25 -05:00
parent d8b225efbe
commit 25342d5876
1 changed files with 41 additions and 38 deletions

View File

@ -818,13 +818,11 @@ 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(
function() {
var deferred = when.defer(); var deferred = when.defer();
var transaction = that.db.transaction([FILE_STORE_NAME], IDB_RW); // var transaction = that.db.transaction([FILE_STORE_NAME], IDB_RW);
var files = transaction.objectStore(FILE_STORE_NAME); // var files = transaction.objectStore(FILE_STORE_NAME);
function check_result(error, fileNode) { function check_result(error, fileNode) {
if(error) { if(error) {
@ -848,7 +846,7 @@ define(function(require) {
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);
@ -857,11 +855,6 @@ define(function(require) {
callback(error); callback(error);
} }
); );
},
function() {
callback(new EFileSystemError('unknown error'));
}
);
}; };
FileSystem.prototype._close = function _close(fd, callback) { FileSystem.prototype._close = function _close(fd, callback) {
var deferred = when.defer(); var deferred = when.defer();
@ -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;