Updated read() error checking. Updated stat() return structure.

This commit is contained in:
Alan Kligman 2012-11-30 19:09:14 -05:00
parent b1b94d91a9
commit baf63c6055
1 changed files with 64 additions and 26 deletions

View File

@ -89,10 +89,10 @@ define(function(require) {
// Compute file signature based on file id and version // Compute file signature based on file id and version
} }
function Stats(size, data, atime, ctime, mtime, links) { function Stats(size, handle, atime, ctime, mtime, links) {
return { return {
size: size, size: size,
data: data, handle: handle,
atime: atime, atime: atime,
ctime: ctime, ctime: ctime,
mtime: mtime, mtime: mtime,
@ -161,6 +161,8 @@ define(function(require) {
if(!_(data).has(name)) { if(!_(data).has(name)) {
if(_(flags).contains(OF_CREATE)) { if(_(flags).contains(OF_CREATE)) {
filehandle = data[name] = hash(guid()); filehandle = data[name] = hash(guid());
++ parent.size;
++ parent.version;
file = new File(); file = new File();
++ file.links; ++ file.links;
var createFileRequest = files.put(file, data[name]); var createFileRequest = files.put(file, data[name]);
@ -237,6 +239,7 @@ define(function(require) {
getParentRequest.onsuccess = function(e) { getParentRequest.onsuccess = function(e) {
var parent = e.target.result; var parent = e.target.result;
parent.data[Path.basename(fullpath)] = directoryhandle; parent.data[Path.basename(fullpath)] = directoryhandle;
++ parent.size;
++ parent.version; ++ parent.version;
var updateParentRequest = files.put(parent, parenthandle); var updateParentRequest = files.put(parent, parenthandle);
updateParentRequest.onsuccess = function(e) { updateParentRequest.onsuccess = function(e) {
@ -286,6 +289,7 @@ define(function(require) {
getParentRequest.onsuccess = function(e) { getParentRequest.onsuccess = function(e) {
var parent = e.target.result; var parent = e.target.result;
delete parent.data[directoryhandle]; delete parent.data[directoryhandle];
-- parent.size;
++ parent.version; ++ parent.version;
var updateParentRequest = files.put(parent, parenthandle); var updateParentRequest = files.put(parent, parenthandle);
updateParentRequest.onsuccess = function(e) { updateParentRequest.onsuccess = function(e) {
@ -331,7 +335,7 @@ define(function(require) {
var getFileRequest = files.get(filehandle); var getFileRequest = files.get(filehandle);
getFileRequest.onsuccess = function(e) { getFileRequest.onsuccess = function(e) {
var file = e.target.result; var file = e.target.result;
var stats = new Stats(file.size, file.data, file.atime, file.ctime, file.mtime, file.links); var stats = new Stats(file.size, filehandle, file.atime, file.ctime, file.mtime, file.links);
runcallback(callback, null, stats); runcallback(callback, null, stats);
}; };
getFileRequest.onerror = function(e) { getFileRequest.onerror = function(e) {
@ -386,7 +390,8 @@ define(function(require) {
runcallback(callback, new error.EPathExists()); runcallback(callback, new error.EPathExists());
} else { } else {
newdata[newname] = filehandle; newdata[newname] = filehandle;
++ parent.version; ++ newparent.size;
++ newparent.version;
var updateNewParentRequest = files.put(newparent, newparenthandle); var updateNewParentRequest = files.put(newparent, newparenthandle);
updateNewParentRequest.onsuccess = function(e) { updateNewParentRequest.onsuccess = function(e) {
runcallback(callback); runcallback(callback);
@ -435,6 +440,8 @@ define(function(require) {
} else { } else {
var filehandle = data[name]; var filehandle = data[name];
delete data[name]; delete data[name];
-- parent.size;
++ parent.version;
var updateParentRequest = files.put(parent, parenthandle); var updateParentRequest = files.put(parent, parenthandle);
updateParentRequest.onsuccess = function(e) { updateParentRequest.onsuccess = function(e) {
var getFileRequest = files.get(filehandle); var getFileRequest = files.get(filehandle);
@ -585,11 +592,15 @@ define(function(require) {
OpenFile.prototype.read = function read(buffer, callback, optTransaction) { OpenFile.prototype.read = function read(buffer, callback, optTransaction) {
var openfile = this; var openfile = this;
var fs = openfile._fs; var fs = openfile._fs;
if(DIRECTORY_MIME_TYPE === openfile._file.mode) {
return runcallback(callback, new error.EIsDir());
}
var transaction = optTransaction || new openfile.Transaction([FILE_STORE_NAME], IDB_RO); var transaction = optTransaction || new openfile.Transaction([FILE_STORE_NAME], IDB_RO);
var files = transaction.objectStore(FILE_STORE_NAME); var files = transaction.objectStore(FILE_STORE_NAME);
if(FILE_MIME_TYPE === openfile._file.mode) {
var getDataRequest = files.get(openfile._file.data); var getDataRequest = files.get(openfile._file.data);
getDataRequest.onsuccess = function(e) { getDataRequest.onsuccess = function(e) {
var data = e.target.result; var data = e.target.result;
@ -609,9 +620,33 @@ define(function(require) {
getDataRequest.onerror = function(e) { getDataRequest.onerror = function(e) {
runcallback(callback, e); runcallback(callback, e);
} }
} else if(DIRECTORY_MIME_TYPE === openfile._file.mode) { };
runcallback(callback, new error.ENotImplemented()); OpenFile.prototype.readdir = function readdir(buffer, count, callback, optTransaction) {
var openfile = this;
var fs = openfile._fs;
if(!DIRECTORY_MIME_TYPE === openfile._file.mode) {
return runcallback(callback, new error.ENotIsDir());
} }
var transaction = optTransaction || new openfile.Transaction([FILE_STORE_NAME], IDB_RO);
var files = transaction.objectStore(FILE_STORE_NAME);
var getFileRequest = files.get(openfile._handle);
getFileRequest.onsuccess = function(e) {
var file = e.target.result;
var names = _(file.data).keys().sort();
count = (openfile._position + count > file.size) ? (file.size - openfile._position) : count;
for(var i = openfile._position, l = openfile._position + count; i < l; ++ i) {
buffer.push(names[i]);
}
openfile._position += count;
runcallback(callback, null, count, buffer);
};
getFileRequest.onerror = function(e) {
runcallback(callback, e);
};
}; };
OpenFile.prototype.write = function write(buffer, callback, optTransaction) { OpenFile.prototype.write = function write(buffer, callback, optTransaction) {
var openfile = this; var openfile = this;
@ -679,6 +714,9 @@ define(function(require) {
FileDescriptor.prototype.read = function read(buffer, callback) { FileDescriptor.prototype.read = function read(buffer, callback) {
this._openfile.read(buffer, callback); this._openfile.read(buffer, callback);
}; };
FileDescriptor.prototype.readdir = function readdir(buffer, count, callback) {
this._openfile.readdir(buffer, count, callback);
};
FileDescriptor.prototype.write = function write(buffer, callback) { FileDescriptor.prototype.write = function write(buffer, callback) {
this._openfile.write(buffer, callback); this._openfile.write(buffer, callback);
}; };