From 23a9861e8280b0a8d50de6760f14976edeed9bff Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Mon, 3 Mar 2014 19:11:31 -0500 Subject: [PATCH 01/16] Deal with provider.open edge case in new provider-agnostic tests. Fixes issue #127. --- tests/spec/adapters/adapters.general.spec.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/spec/adapters/adapters.general.spec.js b/tests/spec/adapters/adapters.general.spec.js index 709b53a..019434d 100644 --- a/tests/spec/adapters/adapters.general.spec.js +++ b/tests/spec/adapters/adapters.general.spec.js @@ -3,7 +3,7 @@ define(["Filer", "util"], function(Filer, util) { // We reuse the same set of tests for all adapters. // buildTestsFor() creates a set of tests bound to an // adapter, and uses the provider set on the query string - // (defaults to Memory, see test-utils.js). + // (defaults to best available/supported provider, see test-utils.js). function buildTestsFor(adapterName, buildAdapter) { function encode(str) { // TextEncoder is either native, or shimmed by Filer @@ -38,7 +38,7 @@ define(["Filer", "util"], function(Filer, util) { }); }); - describe("open a Memory provider with an " + adapterName + " adapter", function() { + describe("open a provider with an " + adapterName + " adapter", function() { beforeEach(util.setup); afterEach(util.cleanup); @@ -46,13 +46,17 @@ define(["Filer", "util"], function(Filer, util) { var provider = createProvider(); provider.open(function(error, firstAccess) { expect(error).not.to.exist; - expect(firstAccess).to.be.true; + // NOTE: we test firstAccess logic in the individual provider tests + // (see tests/spec/providers/*) but can't easily/actually test it here, + // since the provider-agnostic code in test-utils pre-creates a + // FileSystem object, thus eating the first access info. + // See https://github.com/js-platform/filer/issues/127 done(); }); }); }); - describe("Read/Write operations on a Memory provider with an " + adapterName + " adapter", function() { + describe("Read/Write operations on a provider with an " + adapterName + " adapter", function() { beforeEach(util.setup); afterEach(util.cleanup); From da5e1b2b5775b207c7a508341d824f85b7264c26 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Tue, 4 Mar 2014 13:37:37 -0500 Subject: [PATCH 02/16] Fix WebSQL provider to properly deal with typed arrays, 100% of tests passing now on WebKit with WebSQL --- src/providers/websql.js | 47 +++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/src/providers/websql.js b/src/providers/websql.js index 721b775..6da7038 100644 --- a/src/providers/websql.js +++ b/src/providers/websql.js @@ -27,7 +27,7 @@ define(function(require) { callback(null); } this.getTransaction(function(transaction) { - transaction.executeSql("DELETE FROM " + FILE_STORE_NAME, + transaction.executeSql("DELETE FROM " + FILE_STORE_NAME + ";", [], onSuccess, onError); }); }; @@ -35,17 +35,44 @@ define(function(require) { function onSuccess(transaction, result) { // If the key isn't found, return null var value = result.rows.length === 0 ? null : result.rows.item(0).data; - callback(null, value); + try { + if(value) { + value = JSON.parse(value); + // Deal with special-cased flattened typed arrays in WebSQL (see put() below) + if(value.__isUint8Array) { + value = new Uint8Array(value.__array); + } + } + callback(null, value); + } catch(e) { + callback(e); + } } function onError(transaction, error) { callback(error); } this.getTransaction(function(transaction) { - transaction.executeSql("SELECT data FROM " + FILE_STORE_NAME + " WHERE id = ?", + transaction.executeSql("SELECT data FROM " + FILE_STORE_NAME + " WHERE id = ?;", [key], onSuccess, onError); }); }; WebSQLContext.prototype.put = function(key, value, callback) { + // We do extra work to make sure typed arrays survive + // being stored in the db and still get the right prototype later. + if(Object.prototype.toString.call(value) === "[object Uint8Array]") { + value = { + __isUint8Array: true, + __array: (function() { + var array = []; + var vlen = value.length; + for(var i = 0; i < vlen; i++) { + array[i] = value[i]; + } + return array; + }()) + }; + } + value = JSON.stringify(value); function onSuccess(transaction, result) { callback(null); } @@ -53,7 +80,7 @@ define(function(require) { callback(error); } this.getTransaction(function(transaction) { - transaction.executeSql("INSERT OR REPLACE INTO " + FILE_STORE_NAME + " (id, data) VALUES (?, ?)", + transaction.executeSql("INSERT OR REPLACE INTO " + FILE_STORE_NAME + " (id, data) VALUES (?, ?);", [key, value], onSuccess, onError); }); }; @@ -65,7 +92,7 @@ define(function(require) { callback(error); } this.getTransaction(function(transaction) { - transaction.executeSql("DELETE FROM " + FILE_STORE_NAME + " WHERE id = ?", + transaction.executeSql("DELETE FROM " + FILE_STORE_NAME + " WHERE id = ?;", [key], onSuccess, onError); }); }; @@ -113,9 +140,15 @@ define(function(require) { [], gotCount, onError); } + // Create the table and index we'll need to store the fs data. db.transaction(function(transaction) { - transaction.executeSql("CREATE TABLE IF NOT EXISTS " + FILE_STORE_NAME + " (id unique, data)", - [], onSuccess, onError); + function createIndex(transaction) { + transaction.executeSql("CREATE INDEX IF NOT EXISTS idx_" + FILE_STORE_NAME + "_id" + + " on " + FILE_STORE_NAME + " (id);", + [], onSuccess, onError); + } + transaction.executeSql("CREATE TABLE IF NOT EXISTS " + FILE_STORE_NAME + " (id unique, data TEXT);", + [], createIndex, onError); }); }; WebSQL.prototype.getReadOnlyContext = function() { From 32a5cfe584c162f4c7b8e49eaaed51f711e5a7ee Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Tue, 4 Mar 2014 14:32:33 -0500 Subject: [PATCH 03/16] Review fixes --- src/providers/websql.js | 10 ++-------- src/shared.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/providers/websql.js b/src/providers/websql.js index 6da7038..4101de1 100644 --- a/src/providers/websql.js +++ b/src/providers/websql.js @@ -4,6 +4,7 @@ define(function(require) { var WSQL_VERSION = require('src/constants').WSQL_VERSION; var WSQL_SIZE = require('src/constants').WSQL_SIZE; var WSQL_DESC = require('src/constants').WSQL_DESC; + var u8toArray = require('src/shared').u8toArray; function WebSQLContext(db, isReadOnly) { var that = this; @@ -62,14 +63,7 @@ define(function(require) { if(Object.prototype.toString.call(value) === "[object Uint8Array]") { value = { __isUint8Array: true, - __array: (function() { - var array = []; - var vlen = value.length; - for(var i = 0; i < vlen; i++) { - array[i] = value[i]; - } - return array; - }()) + __array: u8toArray(value) }; } value = JSON.stringify(value); diff --git a/src/shared.js b/src/shared.js index a98d1d4..16d9439 100644 --- a/src/shared.js +++ b/src/shared.js @@ -15,9 +15,22 @@ define(function(require) { function nop() {} + /** + * Convert a Uint8Array to a regular array + */ + function u8toArray(u8) { + var array = []; + var len = u8.length; + for(var i = 0; i < len; i++) { + array[i] = u8[i]; + } + return array; + } + return { guid: guid, hash: hash, + u8toArray: u8toArray, nop: nop }; From f10b86b644e2c27e70392d01174989042af22096 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Tue, 4 Mar 2014 15:30:46 -0500 Subject: [PATCH 04/16] Change fs.utime test to remove constant times, prefering calculated duration. Fixes #103 --- tests/spec/fs.utimes.spec.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/spec/fs.utimes.spec.js b/tests/spec/fs.utimes.spec.js index 70c6a5d..253f102 100644 --- a/tests/spec/fs.utimes.spec.js +++ b/tests/spec/fs.utimes.spec.js @@ -158,22 +158,21 @@ define(["Filer", "util"], function(Filer, util) { var fs = util.fs(); var atimeEst; var mtimeEst; - var now; fs.writeFile('/myfile', '', function (error) { if (error) throw error; + var then = Date.now(); fs.utimes('/myfile', null, null, function (error) { expect(error).not.to.exist; - now = Date.now(); - fs.stat('/myfile', function (error, stat) { expect(error).not.to.exist; // Note: testing estimation as time may differ by a couple of milliseconds // This number should be increased if tests are on slow systems - expect(now - stat.atime).to.be.below(75); - expect(now - stat.mtime).to.be.below(75); + var delta = Date.now() - then; + expect(then - stat.atime).to.be.below(delta); + expect(then - stat.mtime).to.be.below(delta); done(); }); }); From bf9ff3ab3a58c1877300eafc5724eed9bceabc36 Mon Sep 17 00:00:00 2001 From: pbouianov Date: Wed, 5 Mar 2014 13:22:23 -0500 Subject: [PATCH 05/16] Updated error object to match Node.js. Solves issue #125. --- src/error.js | 586 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 517 insertions(+), 69 deletions(-) diff --git a/src/error.js b/src/error.js index 686fbf3..4cf22f5 100644 --- a/src/error.js +++ b/src/error.js @@ -9,122 +9,570 @@ Redistribution and use in source and binary forms, with or without modification, Neither the name of the Mozilla Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Errors based off Node.js custom errors (https://github.com/rvagg/node-errno) made available under the MIT license */ define(function(require) { // 'use strict'; - - function EExists(message){ - this.message = message || ''; + + function Unknown(message){ + this.message = message || 'unknown error'; } - EExists.prototype = new Error(); - EExists.prototype.name = "EExists"; - EExists.prototype.constructor = EExists; + Unknown.prototype = new Error(); + Unknown.prototype.errno = -1; + Unknown.prototype.code = "UNKNOWN"; + Unknown.prototype.constructor = Unknown; - function EIsDirectory(message){ - this.message = message || ''; + function OK(message){ + this.message = message || 'success'; } - EIsDirectory.prototype = new Error(); - EIsDirectory.prototype.name = "EIsDirectory"; - EIsDirectory.prototype.constructor = EIsDirectory; + OK.prototype = new Error(); + OK.prototype.errno = 0; + OK.prototype.code = "OK"; + OK.prototype.constructor = OK; - function ENoEntry(message){ - this.message = message || ''; + function EOF(message){ + this.message = message || 'end of file'; } - ENoEntry.prototype = new Error(); - ENoEntry.prototype.name = "ENoEntry"; - ENoEntry.prototype.constructor = ENoEntry; + EOF.prototype = new Error(); + EOF.prototype.errno = 1; + EOF.prototype.code = "EOF"; + EOF.prototype.constructor = EOF; + + function EAddrInfo(message){ + this.message = message || 'getaddrinfo error'; + } + EAddrInfo.prototype = new Error(); + EAddrInfo.prototype.errno = 2; + EAddrInfo.prototype.code = "EADDRINFO"; + EAddrInfo.prototype.constructor = EAddrInfo; + + function EAcces(message){ + this.message = message || 'permission denied'; + } + EAcces.prototype = new Error(); + EAcces.prototype.errno = 3; + EAcces.prototype.code = "EACCES"; + EAcces.prototype.constructor = EAcces; + + function EAgain(message){ + this.message = message || 'resource temporarily unavailable'; + } + EAgain.prototype = new Error(); + EAgain.prototype.errno = 4; + EAgain.prototype.code = "EAGAIN"; + EAgain.prototype.constructor = EAgain; + + function EAddrInUse(message){ + this.message = message || 'address already in use'; + } + EAddrInUse.prototype = new Error(); + EAddrInUse.prototype.errno = 5; + EAddrInUse.prototype.code = "EADDRINUSE"; + EAddrInUse.prototype.constructor = EAddrInUse; + + function EAddrNotAvail(message){ + this.message = message || 'address not available'; + } + EAddrNotAvail.prototype = new Error(); + EAddrNotAvail.prototype.errno = 6; + EAddrNotAvail.prototype.code = "EADDRNOTAVAIL"; + EAddrNotAvail.prototype.constructor = EAddrNotAvail; + + function EAFNoSupport(message){ + this.message = message || 'address family not supported'; + } + EAFNoSupport.prototype = new Error(); + EAFNoSupport.prototype.errno = 7; + EAFNoSupport.prototype.code = "EAFNOSUPPORT"; + EAFNoSupport.prototype.constructor = EAFNoSupport; - function EBusy(message){ - this.message = message || ''; + function EAlready(message){ + this.message = message || 'connection already in progress'; } - EBusy.prototype = new Error(); - EBusy.prototype.name = "EBusy"; - EBusy.prototype.constructor = EBusy; - - function ENotEmpty(message){ - this.message = message || ''; - } - ENotEmpty.prototype = new Error(); - ENotEmpty.prototype.name = "ENotEmpty"; - ENotEmpty.prototype.constructor = ENotEmpty; - - function ENotDirectory(message){ - this.message = message || ''; - } - ENotDirectory.prototype = new Error(); - ENotDirectory.prototype.name = "ENotDirectory"; - ENotDirectory.prototype.constructor = ENotDirectory; + EAlready.prototype = new Error(); + EAlready.prototype.errno = 8; + EAlready.prototype.code = "EALREADY"; + EAlready.prototype.constructor = EAlready; function EBadFileDescriptor(message){ - this.message = message || ''; + this.message = message || 'bad file descriptor'; } EBadFileDescriptor.prototype = new Error(); - EBadFileDescriptor.prototype.name = "EBadFileDescriptor"; + EBadFileDescriptor.prototype.errno = 9; + EBadFileDescriptor.prototype.code = "EBADF"; EBadFileDescriptor.prototype.constructor = EBadFileDescriptor; - function ENotImplemented(message){ - this.message = message || ''; + function EBusy(message){ + this.message = message || 'resource busy or locked'; } - ENotImplemented.prototype = new Error(); - ENotImplemented.prototype.name = "ENotImplemented"; - ENotImplemented.prototype.constructor = ENotImplemented; + EBusy.prototype = new Error(); + EBusy.prototype.errno = 10; + EBusy.prototype.code = "EBUSY"; + EBusy.prototype.constructor = EBusy; - function ENotMounted(message){ - this.message = message || ''; + function EConnAborted(message){ + this.message = message || 'software caused connection abort'; } - ENotMounted.prototype = new Error(); - ENotMounted.prototype.name = "ENotMounted"; - ENotMounted.prototype.constructor = ENotMounted; + EConnAborted.prototype = new Error(); + EConnAborted.prototype.errno = 11; + EConnAborted.prototype.code = "ECONNABORTED"; + EConnAborted.prototype.constructor = EConnAborted; + function EConnRefused(message){ + this.message = message || 'connection refused'; + } + EConnRefused.prototype = new Error(); + EConnRefused.prototype.errno = 12; + EConnRefused.prototype.code = "ECONNREFUSED"; + EConnRefused.prototype.constructor = EConnRefused; + + function EConnReset(message){ + this.message = message || 'connection reset by peer'; + } + EConnReset.prototype = new Error(); + EConnReset.prototype.errno = 13; + EConnReset.prototype.code = "ECONNRESET"; + EConnReset.prototype.constructor = EConnReset; + + function EDestAddrReq(message){ + this.message = message || 'destination address required'; + } + EDestAddrReq.prototype = new Error(); + EDestAddrReq.prototype.errno = 14; + EDestAddrReq.prototype.code = "EDESTADDRREQ"; + EDestAddrReq.prototype.constructor = EDestAddrReq; + + function EFault(message){ + this.message = message || 'bad address in system call argument'; + } + EFault.prototype = new Error(); + EFault.prototype.errno = 15; + EFault.prototype.code = "EFAULT"; + EFault.prototype.constructor = EFault; + + function EHostUnreach(message){ + this.message = message || 'host is unreachable'; + } + EHostUnreach.prototype = new Error(); + EHostUnreach.prototype.errno = 16; + EHostUnreach.prototype.code = "EHOSTUNREACH"; + EHostUnreach.prototype.constructor = EHostUnreach; + + function EIntr(message){ + this.message = message || 'interrupted system call'; + } + EIntr.prototype = new Error(); + EIntr.prototype.errno = 17; + EIntr.prototype.code = "EINTR"; + EIntr.prototype.constructor = EIntr; + function EInvalid(message){ - this.message = message || ''; + this.message = message || 'invalid argument'; } EInvalid.prototype = new Error(); - EInvalid.prototype.name = "EInvalid"; + EInvalid.prototype.errno = 18; + EInvalid.prototype.code = "EINVAL"; EInvalid.prototype.constructor = EInvalid; - function EIO(message){ - this.message = message || ''; + function EIsConn(message){ + this.message = message || 'socket is already connected'; } - EIO.prototype = new Error(); - EIO.prototype.name = "EIO"; - EIO.prototype.constructor = EIO; + EIsConn.prototype = new Error(); + EIsConn.prototype.errno = 19; + EIsConn.prototype.code = "EISCONN"; + EIsConn.prototype.constructor = EIsConn; + + function EMFile(message){ + this.message = message || 'too many open files'; + } + EMFile.prototype = new Error(); + EMFile.prototype.errno = 20; + EMFile.prototype.code = "EMFILE"; + EMFile.prototype.constructor = EMFile; + + function EMsgSize(message){ + this.message = message || 'message too long'; + } + EMsgSize.prototype = new Error(); + EMsgSize.prototype.errno = 21; + EMsgSize.prototype.code = "EMSGSIZE"; + EMsgSize.prototype.constructor = EMsgSize; + + function ENetDown(message){ + this.message = message || 'network is down'; + } + ENetDown.prototype = new Error(); + ENetDown.prototype.errno = 22; + ENetDown.prototype.code = "ENETDOWN"; + ENetDown.prototype.constructor = ENetDown; + + function ENetUnreach(message){ + this.message = message || 'network is unreachable'; + } + ENetUnreach.prototype = new Error(); + ENetUnreach.prototype.errno = 23; + ENetUnreach.prototype.code = "ENETUNREACH"; + ENetUnreach.prototype.constructor = ENetUnreach; + + function ENFile(message){ + this.message = message || 'file table overflow'; + } + ENFile.prototype = new Error(); + ENFile.prototype.errno = 24; + ENFile.prototype.code = "ENFILE"; + ENFile.prototype.constructor = ENFile; + + function ENoBufS(message){ + this.message = message || 'no buffer space available'; + } + ENoBufS.prototype = new Error(); + ENoBufS.prototype.errno = 25; + ENoBufS.prototype.code = "ENOBUFS"; + ENoBufS.prototype.constructor = ENoBufS; + + function ENoMem(message){ + this.message = message || 'not enough memory'; + } + ENoMem.prototype = new Error(); + ENoMem.prototype.errno = 26; + ENoMem.prototype.code = "ENOMEM"; + ENoMem.prototype.constructor = ENoMem; + + function ENotDirectory(message){ + this.message = message || 'not a directory'; + } + ENotDirectory.prototype = new Error(); + ENotDirectory.prototype.errno = 27; + ENotDirectory.prototype.code = "ENOTDIR"; + ENotDirectory.prototype.constructor = ENotDirectory; + + function EIsDirectory(message){ + this.message = message || 'illegal operation on a directory'; + } + EIsDirectory.prototype = new Error(); + EIsDirectory.prototype.errno = 28; + EIsDirectory.prototype.code = "EISDIR"; + EIsDirectory.prototype.constructor = EIsDirectory; + + function ENoNet(message){ + this.message = message || 'machine is not on the network'; + } + ENoNet.prototype = new Error(); + ENoNet.prototype.errno = 29; + ENoNet.prototype.code = "ENONET"; + ENoNet.prototype.constructor = ENoNet; + + function ENotConn(message){ + this.message = message || 'socket is not connected'; + } + ENotConn.prototype = new Error(); + ENotConn.prototype.errno = 31; + ENotConn.prototype.code = "ENOTCONN"; + ENotConn.prototype.constructor = ENotConn; + + function ENotSock(message){ + this.message = message || 'socket operation on non-socket'; + } + ENotSock.prototype = new Error(); + ENotSock.prototype.errno = 32; + ENotSock.prototype.code = "ENOTSOCK"; + ENotSock.prototype.constructor = ENotSock; + + function ENotSup(message){ + this.message = message || 'operation not supported on socket'; + } + ENotSup.prototype = new Error(); + ENotSup.prototype.errno = 33; + ENotSup.prototype.code = "ENOTSUP"; + ENotSup.prototype.constructor = ENotSup; + + function ENoEntry(message){ + this.message = message || 'no such file or directory'; + } + ENoEntry.prototype = new Error(); + ENoEntry.prototype.errno = 34; + ENoEntry.prototype.code = "ENOENT"; + ENoEntry.prototype.constructor = ENoEntry; + + function ENotImplemented(message){ + this.message = message || 'function not implemented'; + } + ENotImplemented.prototype = new Error(); + ENotImplemented.prototype.errno = 35; + ENotImplemented.prototype.code = "ENOSYS"; + ENotImplemented.prototype.constructor = ENotImplemented; + + function EPipe(message){ + this.message = message || 'broken pipe'; + } + EPipe.prototype = new Error(); + EPipe.prototype.errno = 36; + EPipe.prototype.code = "EPIPE"; + EPipe.prototype.constructor = EPipe; + + function EProto(message){ + this.message = message || 'protocol error'; + } + EProto.prototype = new Error(); + EProto.prototype.errno = 37; + EProto.prototype.code = "EPROTO"; + EProto.prototype.constructor = EProto; + + function EProtoNoSupport(message){ + this.message = message || 'protocol not supported'; + } + EProtoNoSupport.prototype = new Error(); + EProtoNoSupport.prototype.errno = 38; + EProtoNoSupport.prototype.code = "EPROTONOSUPPORT"; + EProtoNoSupport.prototype.constructor = EProtoNoSupport; + + function EPrototype(message){ + this.message = message || 'protocol wrong type for socket'; + } + EPrototype.prototype = new Error(); + EPrototype.prototype.errno = 39; + EPrototype.prototype.code = "EPROTOTYPE"; + EPrototype.prototype.constructor = EPrototype; + + function ETimedOut(message){ + this.message = message || 'connection timed out'; + } + ETimedOut.prototype = new Error(); + ETimedOut.prototype.errno = 40; + ETimedOut.prototype.code = "ETIMEDOUT"; + ETimedOut.prototype.constructor = ETimedOut; + + function ECharset(message){ + this.message = message || 'invalid Unicode character'; + } + ECharset.prototype = new Error(); + ECharset.prototype.errno = 41; + ECharset.prototype.code = "ECHARSET"; + ECharset.prototype.constructor = ECharset; + + function EAIFamNoSupport(message){ + this.message = message || 'address family for hostname not supported'; + } + EAIFamNoSupport.prototype = new Error(); + EAIFamNoSupport.prototype.errno = 42; + EAIFamNoSupport.prototype.code = "EAIFAMNOSUPPORT"; + EAIFamNoSupport.prototype.constructor = EAIFamNoSupport; + + function EAIService(message){ + this.message = message || 'servname not supported for ai_socktype'; + } + EAIService.prototype = new Error(); + EAIService.prototype.errno = 44; + EAIService.prototype.code = "EAISERVICE"; + EAIService.prototype.constructor = EAIService; + + function EAISockType(message){ + this.message = message || 'ai_socktype not supported'; + } + EAISockType.prototype = new Error(); + EAISockType.prototype.errno = 45; + EAISockType.prototype.code = "EAISOCKTYPE"; + EAISockType.prototype.constructor = EAISockType; + + function EShutdown(message){ + this.message = message || 'cannot send after transport endpoint shutdown'; + } + EShutdown.prototype = new Error(); + EShutdown.prototype.errno = 46; + EShutdown.prototype.code = "ESHUTDOWN"; + EShutdown.prototype.constructor = EShutdown; + + function EExists(message){ + this.message = message || 'file already exists'; + } + EExists.prototype = new Error(); + EExists.prototype.errno = 47; + EExists.prototype.code = "EEXIST"; + EExists.prototype.constructor = EExists; + + function ESrch(message){ + this.message = message || 'no such process'; + } + ESrch.prototype = new Error(); + ESrch.prototype.errno = 48; + ESrch.prototype.code = "ESRCH"; + ESrch.prototype.constructor = ESrch; + + function ENameTooLong(message){ + this.message = message || 'name too long'; + } + ENameTooLong.prototype = new Error(); + ENameTooLong.prototype.errno = 49; + ENameTooLong.prototype.code = "ENAMETOOLONG"; + ENameTooLong.prototype.constructor = ENameTooLong; + + function EPerm(message){ + this.message = message || 'operation not permitted'; + } + EPerm.prototype = new Error(); + EPerm.prototype.errno = 50; + EPerm.prototype.code = "EPERM"; + EPerm.prototype.constructor = EPerm; function ELoop(message){ - this.message = message || ''; + this.message = message || 'too many symbolic links encountered'; } ELoop.prototype = new Error(); - ELoop.prototype.name = "ELoop"; + ELoop.prototype.errno = 51; + ELoop.prototype.code = "ELOOP"; ELoop.prototype.constructor = ELoop; + function EXDev(message){ + this.message = message || 'cross-device link not permitted'; + } + EXDev.prototype = new Error(); + EXDev.prototype.errno = 52; + EXDev.prototype.code = "EXDEV"; + EXDev.prototype.constructor = EXDev; + + function ENotEmpty(message){ + this.message = message || 'directory not empty'; + } + ENotEmpty.prototype = new Error(); + ENotEmpty.prototype.errno = 53; + ENotEmpty.prototype.code = "ENOTEMPTY"; + ENotEmpty.prototype.constructor = ENotEmpty; + + function ENoSpc(message){ + this.message = message || 'no space left on device'; + } + ENoSpc.prototype = new Error(); + ENoSpc.prototype.errno = 54; + ENoSpc.prototype.code = "ENOSPC"; + ENoSpc.prototype.constructor = ENoSpc; + + function EIO(message){ + this.message = message || 'i/o error'; + } + EIO.prototype = new Error(); + EIO.prototype.errno = 55; + EIO.prototype.code = "EIO"; + EIO.prototype.constructor = EIO; + + function EROFS(message){ + this.message = message || 'read-only file system'; + } + EROFS.prototype = new Error(); + EROFS.prototype.errno = 56; + EROFS.prototype.code = "EROFS"; + EROFS.prototype.constructor = EROFS; + + function ENoDev(message){ + this.message = message || 'no such device'; + } + ENoDev.prototype = new Error(); + ENoDev.prototype.errno = 57; + ENoDev.prototype.code = "ENODEV"; + ENoDev.prototype.constructor = ENoDev; + + function ESPipe(message){ + this.message = message || 'invalid seek'; + } + ESPipe.prototype = new Error(); + ESPipe.prototype.errno = 58; + ESPipe.prototype.code = "ESPIPE"; + ESPipe.prototype.constructor = ESPipe; + + function ECanceled(message){ + this.message = message || 'operation canceled'; + } + ECanceled.prototype = new Error(); + ECanceled.prototype.errno = 59; + ECanceled.prototype.code = "ECANCELED"; + ECanceled.prototype.constructor = ECanceled; + + function ENotMounted(message){ + this.message = message || 'not mounted'; + } + ENotMounted.prototype = new Error(); + ENotMounted.prototype.errno = 60; + ENotMounted.prototype.code = "ENotMounted"; + ENotMounted.prototype.constructor = ENotMounted; + function EFileSystemError(message){ - this.message = message || ''; + this.message = message || 'missing super node'; } EFileSystemError.prototype = new Error(); - EFileSystemError.prototype.name = "EFileSystemError"; + EFileSystemError.prototype.errno = 61; + EFileSystemError.prototype.code = "EFileSystemError"; EFileSystemError.prototype.constructor = EFileSystemError; function ENoAttr(message) { - this.message = message || ''; + this.message = message || 'attribute does not exist'; } ENoAttr.prototype = new Error(); - ENoAttr.prototype.name = 'ENoAttr'; + ENoAttr.prototype.errno = 62; + ENoAttr.prototype.code = 'ENoAttr'; ENoAttr.prototype.constructor = ENoAttr; return { - EExists: EExists, - EIsDirectory: EIsDirectory, - ENoEntry: ENoEntry, - EBusy: EBusy, - ENotEmpty: ENotEmpty, - ENotDirectory: ENotDirectory, + Unknown: Unknown, + OK: OK, + EOF: EOF, + EAddrInfo: EAddrInfo, + EAcces: EAcces, + EAgain: EAgain, + EAddrInUse: EAddrInUse, + EAddrNotAvail: EAddrNotAvail, + EAFNoSupport: EAFNoSupport, + EAlready: EAlready, EBadFileDescriptor: EBadFileDescriptor, - ENotImplemented: ENotImplemented, - ENotMounted: ENotMounted, + EBusy: EBusy, + EConnAborted: EConnAborted, + EConnRefused: EConnRefused, + EConnReset: EConnReset, + EDestAddrReq: EDestAddrReq, + EFault: EFault, + EHostUnreach: EHostUnreach, + EIntr: EIntr, EInvalid: EInvalid, - EIO: EIO, + EIsConn: EIsConn, + EMFile: EMFile, + EMsgSize: EMsgSize, + ENetDown: ENetDown, + ENetUnreach: ENetUnreach, + ENFile: ENFile, + ENoBufS: ENoBufS, + ENoMem: ENoMem, + ENotDirectory: ENotDirectory, + EIsDirectory: EIsDirectory, + ENoNet: ENoNet, + ENotConn: ENotConn, + ENotSock: ENotSock, + ENotSup: ENotSup, + ENoEntry: ENoEntry, + ENotImplemented: ENotImplemented, + EPipe: EPipe, + EProto: EProto, + EProtoNoSupport: EProtoNoSupport, + EPrototype: EPrototype, + ETimedOut: ETimedOut, + ECharset: ECharset, + EAIFamNoSupport: EAIFamNoSupport, + EAIService: EAIService, + EAISockType: EAISockType, + EShutdown: EShutdown, + EExists: EExists, + ESrch: ESrch, + ENameTooLong: ENameTooLong, + EPerm: EPerm, ELoop: ELoop, + EXDev: EXDev, + ENotEmpty: ENotEmpty, + ENoSpc: ENoSpc, + EIO: EIO, + EROFS: EROFS, + ENoDev: ENoDev, + ESPipe: ESPipe, + ECanceled: ECanceled, + ENotMounted: ENotMounted, EFileSystemError: EFileSystemError, ENoAttr: ENoAttr }; From c5ed7d4a551188c0b892972ee1bc1b95a9c767d8 Mon Sep 17 00:00:00 2001 From: pbouianov Date: Wed, 5 Mar 2014 14:28:31 -0500 Subject: [PATCH 06/16] Updated tests already checking error name --- tests/spec/fs.utimes.spec.js | 12 ++++++------ tests/spec/fs.xattr.spec.js | 28 ++++++++++++++-------------- tests/spec/path-resolution.spec.js | 2 +- tests/spec/shell/cd.spec.js | 4 ++-- tests/spec/shell/rm.spec.js | 2 +- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/spec/fs.utimes.spec.js b/tests/spec/fs.utimes.spec.js index 253f102..4b3cb8e 100644 --- a/tests/spec/fs.utimes.spec.js +++ b/tests/spec/fs.utimes.spec.js @@ -17,7 +17,7 @@ define(["Filer", "util"], function(Filer, util) { fs.utimes('/testfile', -1, Date.now(), function (error) { expect(error).to.exist; - expect(error.name).to.equal('EInvalid'); + expect(error.code).to.equal('EINVAL'); done(); }); }); @@ -31,7 +31,7 @@ define(["Filer", "util"], function(Filer, util) { fs.utimes('/testfile', Date.now(), -1, function (error) { expect(error).to.exist; - expect(error.name).to.equal('EInvalid'); + expect(error.code).to.equal('EINVAL'); done(); }); }); @@ -45,7 +45,7 @@ define(["Filer", "util"], function(Filer, util) { fs.utimes('/testfile', 'invalid datetime', Date.now(), function (error) { expect(error).to.exist; - expect(error.name).to.equal('EInvalid'); + expect(error.code).to.equal('EINVAL'); done(); }); }); @@ -58,7 +58,7 @@ define(["Filer", "util"], function(Filer, util) { fs.utimes('/pathdoesnotexist', atime, mtime, function (error) { expect(error).to.exist; - expect(error.name).to.equal('ENoEntry'); + expect(error.code).to.equal('ENOENT'); done(); }); }); @@ -71,7 +71,7 @@ define(["Filer", "util"], function(Filer, util) { fs.utimes('/testfile', Date.now(), 'invalid datetime', function (error) { expect(error).to.exist; - expect(error.name).to.equal('EInvalid'); + expect(error.code).to.equal('EINVAL'); done(); }); }); @@ -84,7 +84,7 @@ define(["Filer", "util"], function(Filer, util) { fs.futimes(1, atime, mtime, function (error) { expect(error).to.exist; - expect(error.name).to.equal('EBadFileDescriptor'); + expect(error.code).to.equal('EBADF'); done(); }); }); diff --git a/tests/spec/fs.xattr.spec.js b/tests/spec/fs.xattr.spec.js index bb1bf80..618d94b 100644 --- a/tests/spec/fs.xattr.spec.js +++ b/tests/spec/fs.xattr.spec.js @@ -21,7 +21,7 @@ define(["Filer", "util"], function(Filer, util) { fs.setxattr('/testfile', 89, 'testvalue', function (error) { expect(error).to.exist; - expect(error.name).to.equal('EInvalid'); + expect(error.code).to.equal('EINVAL'); done(); }); }); @@ -35,7 +35,7 @@ define(["Filer", "util"], function(Filer, util) { fs.setxattr('/testfile', null, 'testvalue', function (error) { expect(error).to.exist; - expect(error.name).to.equal('EInvalid'); + expect(error.code).to.equal('EINVAL'); done(); }); }); @@ -49,7 +49,7 @@ define(["Filer", "util"], function(Filer, util) { fs.setxattr('/testfile', 'test', 'value', 'InvalidFlag', function (error) { expect(error).to.exist; - expect(error.name).to.equal('EInvalid'); + expect(error.code).to.equal('EINVAL'); done(); }); }); @@ -66,7 +66,7 @@ define(["Filer", "util"], function(Filer, util) { fs.setxattr('/testfile', 'test', 'othervalue', 'CREATE', function(error) { expect(error).to.exist; - expect(error.name).to.equal('EExists'); + expect(error.code).to.equal('EEXIST'); done(); }); }); @@ -81,7 +81,7 @@ define(["Filer", "util"], function(Filer, util) { fs.setxattr('/testfile', 'test', 'value', 'REPLACE', function(error) { expect(error).to.exist; - expect(error.name).to.equal('ENoAttr'); + expect(error.code).to.equal('ENoAttr'); done(); }); }); @@ -95,7 +95,7 @@ define(["Filer", "util"], function(Filer, util) { fs.getxattr('/testfile', '', function(error, value) { expect(error).to.exist; - expect(error.name).to.equal('EInvalid'); + expect(error.code).to.equal('EINVAL'); done(); }); }); @@ -109,7 +109,7 @@ define(["Filer", "util"], function(Filer, util) { fs.getxattr('/testfile', 89, function(error, value) { expect(error).to.exist; - expect(error.name).to.equal('EInvalid'); + expect(error.code).to.equal('EINVAL'); done(); }); }); @@ -123,7 +123,7 @@ define(["Filer", "util"], function(Filer, util) { fs.getxattr('/testfile', 'test', function(error, value) { expect(error).to.exist; - expect(error.name).to.equal('ENoAttr'); + expect(error.code).to.equal('ENoAttr'); done(); }); }); @@ -144,14 +144,14 @@ define(["Filer", "util"], function(Filer, util) { fs.fsetxattr(1, 'test', 'value', function(error) { expect(error).to.exist; - expect(error.name).to.equal('EBadFileDescriptor'); + expect(error.code).to.equal('EBADF'); completeSet = true; maybeDone(); }); fs.fgetxattr(1, 'test', function(error, value) { expect(error).to.exist; - expect(error.name).to.equal('EBadFileDescriptor'); + expect(error.code).to.equal('EBADF'); expect(value).not.to.exist; completeGet = true; maybeDone(); @@ -159,7 +159,7 @@ define(["Filer", "util"], function(Filer, util) { fs.fremovexattr(1, 'test', function(error, value) { expect(error).to.exist; - expect(error.name).to.equal('EBadFileDescriptor'); + expect(error.code).to.equal('EBADF'); completeRemove = true; maybeDone(); }); @@ -195,7 +195,7 @@ define(["Filer", "util"], function(Filer, util) { fs.removexattr('/testfile', 'testenoattr', function (error) { expect(error).to.exist; - expect(error.name).to.equal('ENoAttr'); + expect(error.code).to.equal('ENoAttr'); done(); }); }); @@ -336,7 +336,7 @@ define(["Filer", "util"], function(Filer, util) { fs.getxattr('/testfile', 'test', function (error) { expect(error).to.exist; - expect(error.name).to.equal('ENoAttr'); + expect(error.code).to.equal('ENoAttr'); done(); }); }); @@ -363,7 +363,7 @@ define(["Filer", "util"], function(Filer, util) { fs.fgetxattr(ofd, 'test', function (error) { expect(error).to.exist; - expect(error.name).to.equal('ENoAttr'); + expect(error.code).to.equal('ENoAttr'); done(); }); }); diff --git a/tests/spec/path-resolution.spec.js b/tests/spec/path-resolution.spec.js index 0fa0330..6553be8 100644 --- a/tests/spec/path-resolution.spec.js +++ b/tests/spec/path-resolution.spec.js @@ -149,7 +149,7 @@ define(["Filer", "util"], function(Filer, util) { createSymlinkChain(1, function() { fs.stat('/myfile11', function(error, result) { expect(error).to.exist; - expect(error.name).to.equal('ELoop'); + expect(error.code).to.equal('ELOOP'); expect(result).not.to.exist; done(); }); diff --git a/tests/spec/shell/cd.spec.js b/tests/spec/shell/cd.spec.js index 02bb90b..308cb7f 100644 --- a/tests/spec/shell/cd.spec.js +++ b/tests/spec/shell/cd.spec.js @@ -40,7 +40,7 @@ define(["Filer", "util"], function(Filer, util) { expect(shell.pwd()).to.equal('/'); shell.cd('/nodir', function(err) { expect(err).to.exist; - expect(err.name).to.equal('ENotDirectory'); + expect(err.code).to.equal('ENOTDIR'); expect(shell.pwd()).to.equal('/'); done(); }); @@ -57,7 +57,7 @@ define(["Filer", "util"], function(Filer, util) { expect(shell.pwd()).to.equal('/'); shell.cd('/file', function(err) { expect(err).to.exist; - expect(err.name).to.equal('ENotDirectory'); + expect(err.code).to.equal('ENOTDIR'); expect(shell.pwd()).to.equal('/'); done(); }); diff --git a/tests/spec/shell/rm.spec.js b/tests/spec/shell/rm.spec.js index 628e03f..bae180e 100644 --- a/tests/spec/shell/rm.spec.js +++ b/tests/spec/shell/rm.spec.js @@ -71,7 +71,7 @@ define(["Filer", "util"], function(Filer, util) { shell.rm('/dir', function(err) { expect(err).to.exist; - expect(err.name).to.equal('ENotEmpty'); + expect(err.code).to.equal('ENOTEMPTY'); done(); }); }); From fe9b94d4eccd4f830e63c412e44d5ba15319fdd0 Mon Sep 17 00:00:00 2001 From: pbouianov Date: Wed, 5 Mar 2014 14:45:59 -0500 Subject: [PATCH 07/16] Changed IndexedDB provider to use RW context if RO is requested. Fixes issue #128 --- src/providers/indexeddb.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/providers/indexeddb.js b/src/providers/indexeddb.js index 9de9e9a..2658163 100644 --- a/src/providers/indexeddb.js +++ b/src/providers/indexeddb.js @@ -116,7 +116,10 @@ define(function(require) { }; }; IndexedDB.prototype.getReadOnlyContext = function() { - return new IndexedDBContext(this.db, IDB_RO); + // Due to timing issues in Chrome with readwrite vs. readonly indexeddb transactions + // always use readwrite so we can make sure pending commits finish before callbacks. + // See https://github.com/js-platform/filer/issues/128 + return new IndexedDBContext(this.db, IDB_RW); }; IndexedDB.prototype.getReadWriteContext = function() { return new IndexedDBContext(this.db, IDB_RW); From 1fdd9ac4765ae63a76f50086979039b02296c154 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Tue, 4 Mar 2014 20:50:35 -0500 Subject: [PATCH 08/16] Initial work refactoring updates to node times --- src/fs.js | 91 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 24 deletions(-) diff --git a/src/fs.js b/src/fs.js index 1af666e..42be0fd 100644 --- a/src/fs.js +++ b/src/fs.js @@ -70,7 +70,8 @@ define(function(require) { * OpenFileDescription */ - function OpenFileDescription(id, flags, position) { + function OpenFileDescription(path, id, flags, position) { + this.path = path; this.id = id; this.flags = flags; this.position = position; @@ -102,7 +103,7 @@ define(function(require) { this.mode = mode || MODE_FILE; // node type (file, directory, etc) this.size = size || 0; // size (bytes for files, entries for directories) this.atime = atime || now; // access time - this.ctime = ctime || now; // creation time + this.ctime = ctime || now; // creation/change time this.mtime = mtime || now; // modified time this.flags = flags || []; // file flags this.xattrs = xattrs || {}; // extended attributes @@ -128,6 +129,23 @@ define(function(require) { this.type = fileNode.mode; } + /* + * Update node times. Only passed times are modified (undefined times are ignored) + */ + function update_node_times(context, path, node, times, callback) { + if(times.ctime) { + node.ctime = times.ctime; + } + if(times.mtime) { + node.mtime = times.mtime; + } + if(times.atime) { + node.atime = times.atime; + } + + context.put(node.id, node, callback); + } + /* * find_node */ @@ -596,11 +614,20 @@ define(function(require) { } } + function update_time(error) { + if(error) { + callback(error); + } else { + var now = Date.now(); + update_node_times(context, ofd.path, fileNode, { mtime: now, ctime: now }, return_nbytes); + } + } + function update_file_node(error) { if(error) { callback(error); } else { - context.put(fileNode.id, fileNode, return_nbytes); + context.put(fileNode.id, fileNode, update_time); } } @@ -615,7 +642,6 @@ define(function(require) { ofd.position = length; fileNode.size = length; - fileNode.mtime = Date.now(); fileNode.version += 1; context.put(fileNode.data, newData, update_file_node); @@ -637,11 +663,20 @@ define(function(require) { } } + function update_time(error) { + if(error) { + callback(error); + } else { + var now = Date.now(); + update_node_times(context, ofd.path, fileNode, { mtime: now, ctime: now }, return_nbytes); + } + } + function update_file_node(error) { if(error) { callback(error); } else { - context.put(fileNode.id, fileNode, return_nbytes); + context.put(fileNode.id, fileNode, update_time); } } @@ -663,7 +698,6 @@ define(function(require) { } fileNode.size = newSize; - fileNode.mtime = Date.now(); fileNode.version += 1; context.put(fileNode.data, newData, update_file_node); @@ -1089,14 +1123,22 @@ define(function(require) { } } + function update_time(error) { + if(error) { + callback(error); + } else { + var now = Date.now(); + update_node_times(context, path, fileNode, { mtime: now, ctime: now }, callback); + } + } + function update_file_node (error) { if(error) { callback(error); } else { fileNode.size = length; - fileNode.mtime = Date.now(); fileNode.version += 1; - context.put(fileNode.id, fileNode, callback); + context.put(fileNode.id, fileNode, update_time); } } @@ -1133,14 +1175,21 @@ define(function(require) { } } + function update_time(error) { + if(error) { + callback(error); + } else { + var now = Date.now(); + update_node_times(context, ofd.path, fileNode, { mtime: now, ctime: now }, callback); + } + } function update_file_node (error) { if(error) { callback(error); } else { fileNode.size = length; - fileNode.mtime = Date.now(); fileNode.version += 1; - context.put(fileNode.id, fileNode, callback); + context.put(fileNode.id, fileNode, update_time); } } @@ -1157,11 +1206,8 @@ define(function(require) { function update_times (error, node) { if (error) { callback(error); - } - else { - node.atime = atime; - node.mtime = mtime; - context.put(node.id, node, callback); + } else { + update_node_times(context, path, node, { atime: atime, ctime: mtime, mtime: mtime }, callback); } } @@ -1181,11 +1227,8 @@ define(function(require) { function update_times (error, node) { if (error) { callback(error); - } - else { - node.atime = atime; - node.mtime = mtime; - context.put(node.id, node, callback); + } else { + update_node_times(context, ofd.path, node, { atime: atime, ctime: mtime, mtime: mtime }, callback); } } @@ -1520,7 +1563,7 @@ define(function(require) { } else { position = 0; } - var openFileDescription = new OpenFileDescription(fileNode.id, flags, position); + var openFileDescription = new OpenFileDescription(path, fileNode.id, flags, position); var fd = fs.allocDescriptor(openFileDescription); callback(null, fd); } @@ -1671,7 +1714,7 @@ define(function(require) { if(err) { return callback(err); } - var ofd = new OpenFileDescription(fileNode.id, flags, 0); + var ofd = new OpenFileDescription(path, fileNode.id, flags, 0); var fd = fs.allocDescriptor(ofd); fstat_file(context, ofd, function(err2, fstatResult) { @@ -1748,7 +1791,7 @@ define(function(require) { if(err) { return callback(err); } - var ofd = new OpenFileDescription(fileNode.id, flags, 0); + var ofd = new OpenFileDescription(path, fileNode.id, flags, 0); var fd = fs.allocDescriptor(ofd); replace_data(context, ofd, data, 0, data.length, function(err2, nbytes) { @@ -1783,7 +1826,7 @@ define(function(require) { if(err) { return callback(err); } - var ofd = new OpenFileDescription(fileNode.id, flags, fileNode.size); + var ofd = new OpenFileDescription(path, fileNode.id, flags, fileNode.size); var fd = fs.allocDescriptor(ofd); write_data(context, ofd, data, 0, data.length, ofd.position, function(err2, nbytes) { From 61111da85d03cac6128690aaa943a4073b4a8898 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Wed, 5 Mar 2014 15:57:11 -0500 Subject: [PATCH 09/16] Finish atime, ctime, mtime updates for fs operations, fix tests --- src/constants.js | 4 + src/fs.js | 180 +++++++++++++++++++++++++++++---- tests/spec/fs.exists.spec.js | 27 ++--- tests/spec/fs.link.spec.js | 10 +- tests/spec/fs.utimes.spec.js | 3 - tests/spec/shell/touch.spec.js | 1 - 6 files changed, 186 insertions(+), 39 deletions(-) diff --git a/src/constants.js b/src/constants.js index 74871ae..50b1e2e 100644 --- a/src/constants.js +++ b/src/constants.js @@ -58,6 +58,10 @@ define(function(require) { XATTR_CREATE: XATTR_CREATE, XATTR_REPLACE: XATTR_REPLACE, + NOATIME: 'NOATIME', + NOCTIME: 'NOCTIME', + NOMTIME: 'NOMTIME', + FS_READY: 'READY', FS_PENDING: 'PENDING', FS_ERROR: 'ERROR', diff --git a/src/fs.js b/src/fs.js index 42be0fd..483e806 100644 --- a/src/fs.js +++ b/src/fs.js @@ -52,6 +52,9 @@ define(function(require) { var O_FLAGS = require('src/constants').O_FLAGS; var XATTR_CREATE = require('src/constants').XATTR_CREATE; var XATTR_REPLACE = require('src/constants').XATTR_REPLACE; + var NOATIME = require('src/constants').NOATIME; + var NOMTIME = require('src/constants').NOMTIME; + var NOCTIME = require('src/constants').NOCTIME; var providers = require('src/providers/providers'); var adapters = require('src/adapters/adapters'); @@ -131,19 +134,41 @@ define(function(require) { /* * Update node times. Only passed times are modified (undefined times are ignored) + * and filesystem flags are examined in order to override update logic. */ function update_node_times(context, path, node, times, callback) { + // Honour mount flags for how we update times + var flags = context.flags; + if(_(flags).contains(NOCTIME)) { + delete times.ctime; + } + if(_(flags).contains(NOATIME)) { + delete times.atime; + } + if(_(flags).contains(NOMTIME)) { + delete times.mtime; + } + + // Only do the update if required (i.e., times are still present) + var update = false; if(times.ctime) { node.ctime = times.ctime; - } - if(times.mtime) { - node.mtime = times.mtime; + update = true; } if(times.atime) { node.atime = times.atime; + update = true; + } + if(times.mtime) { + node.mtime = times.mtime; + update = true; } - context.put(node.id, node, callback); + if(update) { + context.put(node.id, node, callback); + } else { + callback(); + } } /* @@ -249,9 +274,19 @@ define(function(require) { */ function set_extended_attribute (context, path_or_fd, name, value, flag, callback) { + var path; + function set_xattr (error, node) { var xattr = (node ? node.xattrs[name] : null); + function update_time(error) { + if(error) { + callback(error); + } else { + update_node_times(context, path, node, { ctime: Date.now() }, callback); + } + } + if (error) { callback(error); } @@ -263,14 +298,16 @@ define(function(require) { } else { node.xattrs[name] = value; - context.put(node.id, node, callback); + context.put(node.id, node, update_time); } } if (typeof path_or_fd == 'string') { + path = path_or_fd; find_node(context, path_or_fd, set_xattr); } else if (typeof path_or_fd == 'object' && typeof path_or_fd.id == 'string') { + path = path_or_fd.path; context.get(path_or_fd.id, set_xattr); } else { @@ -374,12 +411,21 @@ define(function(require) { } } + function update_time(error) { + if(error) { + callback(error); + } else { + var now = Date.now(); + update_node_times(context, parentPath, parentDirectoryNode, { mtime: now, ctime: now }, callback); + } + } + function update_parent_directory_data(error) { if(error) { callback(error); } else { parentDirectoryData[name] = new DirectoryEntry(directoryNode.id, MODE_DIRECTORY); - context.put(parentDirectoryNode.data, parentDirectoryData, callback); + context.put(parentDirectoryNode.data, parentDirectoryData, update_time); } } @@ -447,9 +493,18 @@ define(function(require) { } } + function update_time(error) { + if(error) { + callback(error); + } else { + var now = Date.now(); + update_node_times(context, parentPath, parentDirectoryNode, { mtime: now, ctime: now }, remove_directory_node); + } + } + function remove_directory_entry_from_parent_directory_node() { delete parentDirectoryData[name]; - context.put(parentDirectoryNode.data, parentDirectoryData, remove_directory_node); + context.put(parentDirectoryNode.data, parentDirectoryData, update_time); } function remove_directory_node(error) { @@ -566,7 +621,9 @@ define(function(require) { callback(error); } else { fileNode = result; - callback(null, fileNode); + update_node_times(context, path, fileNode, { atime: Date.now() }, function(error) { + callback(error, fileNode); + }); } } @@ -585,12 +642,21 @@ define(function(require) { } } + function update_time(error) { + if(error) { + callback(error); + } else { + var now = Date.now(); + update_node_times(context, parentPath, directoryNode, { mtime: now, ctime: now }, handle_update_result); + } + } + function update_directory_data(error) { if(error) { callback(error); } else { directoryData[name] = new DirectoryEntry(fileNode.id, MODE_FILE); - context.put(directoryNode.data, directoryData, handle_update_result); + context.put(directoryNode.data, directoryData, update_time); } } @@ -736,12 +802,26 @@ define(function(require) { } } + function update_time(error) { + if(error) { + callback(error); + } else { + + } + } + function read_file_data(error, result) { if(error) { callback(error); } else { fileNode = result; - context.get(fileNode.data, handle_file_data); + update_node_times(context, ofd.path, fileNode, { atime: Date.now() }, function(error) { + if(error) { + callback(error); + } else { + context.get(fileNode.data, handle_file_data); + } + }); } } @@ -756,7 +836,9 @@ define(function(require) { if(error) { callback(error); } else { - callback(null, result); + update_node_times(context, path, result, { atime: Date.now() }, function(error) { + callback(error, result); + }); } } @@ -768,7 +850,9 @@ define(function(require) { if(error) { callback(error); } else { - callback(null, result); + update_node_times(context, ofd.path, result, { atime: Date.now() }, function(error) { + callback(error, result); + }); } } @@ -815,7 +899,9 @@ define(function(require) { if(error) { callback(error); } else { - callback(null, result); + update_node_times(context, path, result, { atime: Date.now() }, function(error) { + callback(error, result); + }); } } } @@ -835,13 +921,21 @@ define(function(require) { var newDirectoryData; var fileNode; + function update_time(error) { + if(error) { + callback(error); + } else { + update_node_times(context, newpath, fileNode, { ctime: Date.now() }, callback); + } + } + function update_file_node(error, result) { if(error) { callback(error); } else { fileNode = result; fileNode.nlinks += 1; - context.put(fileNode.id, fileNode, callback); + context.put(fileNode.id, fileNode, update_time); } } @@ -915,7 +1009,10 @@ define(function(require) { callback(error); } else { delete directoryData[name]; - context.put(directoryNode.data, directoryData, callback); + context.put(directoryNode.data, directoryData, function(error) { + var now = Date.now(); + update_node_times(context, parentPath, directoryNode, { mtime: now, ctime: now }, callback); + }); } } @@ -936,7 +1033,9 @@ define(function(require) { if(fileNode.nlinks < 1) { context.delete(fileNode.id, delete_file_data); } else { - context.put(fileNode.id, fileNode, update_directory_data); + context.put(fileNode.id, fileNode, function(error) { + update_node_times(context, path, fileNode, { ctime: Date.now() }, update_directory_data); + }); } } } @@ -1040,12 +1139,21 @@ define(function(require) { context.put(fileNode.id, fileNode, update_directory_data); } + function update_time(error) { + if(error) { + callback(error); + } else { + var now = Date.now(); + update_node_times(context, parentPath, directoryNode, { mtime: now, ctime: now }, callback); + } + } + function update_directory_data(error) { if(error) { callback(error); } else { directoryData[name] = new DirectoryEntry(fileNode.id, MODE_SYMBOLIC_LINK); - context.put(directoryNode.data, directoryData, callback); + context.put(directoryNode.data, directoryData, update_time); } } } @@ -1203,7 +1311,7 @@ define(function(require) { function utimes_file(context, path, atime, mtime, callback) { path = normalize(path); - function update_times (error, node) { + function update_times(error, node) { if (error) { callback(error); } else { @@ -1339,6 +1447,14 @@ define(function(require) { function remove_xattr (error, node) { var xattr = (node ? node.xattrs : null); + function update_time(error) { + if(error) { + callback(error); + } else { + update_node_times(context, path, node, { ctime: Date.now() }, callback); + } + } + if (error) { callback(error); } @@ -1347,7 +1463,7 @@ define(function(require) { } else { delete node.xattrs[name]; - context.put(node.id, node, callback); + context.put(node.id, node, update_time); } } @@ -1365,6 +1481,14 @@ define(function(require) { function fremovexattr_file (context, ofd, name, callback) { function remove_xattr (error, node) { + function update_time(error) { + if(error) { + callback(error); + } else { + update_node_times(context, ofd.path, node, { ctime: Date.now() }, callback); + } + } + if (error) { callback(error); } @@ -1373,7 +1497,7 @@ define(function(require) { } else { delete node.xattrs[name]; - context.put(node.id, node, callback); + context.put(node.id, node, update_time); } } @@ -1514,7 +1638,21 @@ define(function(require) { // Open file system storage provider provider.open(function(err, needsFormatting) { function complete(error) { - fs.provider = provider; + // Wrap the provider so we can extend the context with fs flags. + // From this point forward we won't call open again, so drop it. + fs.provider = { + getReadWriteContext: function() { + var context = provider.getReadWriteContext(); + context.flags = flags; + return context; + }, + getReadOnlyContext: function() { + var context = provider.getReadOnlyContext(); + context.flags = flags; + return context; + } + }; + if(error) { fs.readyState = FS_ERROR; } else { diff --git a/tests/spec/fs.exists.spec.js b/tests/spec/fs.exists.spec.js index ff8bc03..5000d05 100644 --- a/tests/spec/fs.exists.spec.js +++ b/tests/spec/fs.exists.spec.js @@ -11,9 +11,9 @@ define(["Filer", "util"], function(Filer, util) { it('should return false if path does not exist', function(done) { var fs = util.fs(); - fs.exists('/tmp', function(result) { - expect(result).to.exist; - expect(result).equals(false); + + fs.exists('/tmp', function(result) { + expect(result).to.be.false; done(); }); }); @@ -22,30 +22,33 @@ define(["Filer", "util"], function(Filer, util) { var fs = util.fs(); fs.open('/myfile', 'w', function(err, fd) { + if(err) throw err; + + fs.close(fd, function(err) { if(err) throw err; - fs.close(fd, function(err) { - if(err) throw err; - fs.exists('/myfile', function(result) { - expect(result).to.exist; - expect(result).equals(true); - done(); - }); + + fs.exists('/myfile', function(result) { + expect(result).to.be.true; + done(); }); }); }); + }); it('should follow symbolic links and return true for the resulting path', function(done) { var fs = util.fs(); fs.open('/myfile', 'w', function(error, fd) { if(error) throw error; + fs.close(fd, function(error) { if(error) throw error; + fs.symlink('/myfile', '/myfilelink', function(error) { if(error) throw error; + fs.exists('/myfilelink', function(result) { - expect(result).to.exist; - expect(result).equals(true); + expect(result).to.be.true; done(); }); }); diff --git a/tests/spec/fs.link.spec.js b/tests/spec/fs.link.spec.js index d6ad840..b4db747 100644 --- a/tests/spec/fs.link.spec.js +++ b/tests/spec/fs.link.spec.js @@ -28,7 +28,10 @@ define(["Filer", "util"], function(Filer, util) { fs.stat('/myotherfile', function(error, result) { expect(error).not.to.exist; expect(result.nlinks).to.equal(2); - expect(result).to.deep.equal(_oldstats); + expect(result.dev).to.equal(_oldstats.dev); + expect(result.node).to.equal(_oldstats.node); + expect(result.size).to.equal(_oldstats.size); + expect(result.type).to.equal(_oldstats.type); done(); }); }); @@ -52,7 +55,10 @@ define(["Filer", "util"], function(Filer, util) { var _linkstats = result; fs.lstat('/myotherfile', function (error, result) { expect(error).not.to.exist; - expect(result).to.deep.equal(_linkstats); + expect(result.dev).to.equal(_linkstats.dev); + expect(result.node).to.equal(_linkstats.node); + expect(result.size).to.equal(_linkstats.size); + expect(result.type).to.equal(_linkstats.type); expect(result.nlinks).to.equal(2); done(); }); diff --git a/tests/spec/fs.utimes.spec.js b/tests/spec/fs.utimes.spec.js index 253f102..f87970f 100644 --- a/tests/spec/fs.utimes.spec.js +++ b/tests/spec/fs.utimes.spec.js @@ -102,7 +102,6 @@ define(["Filer", "util"], function(Filer, util) { fs.stat('/testfile', function (error, stat) { expect(error).not.to.exist; - expect(stat.atime).to.equal(atime); expect(stat.mtime).to.equal(mtime); done(); }); @@ -125,7 +124,6 @@ define(["Filer", "util"], function(Filer, util) { fs.fstat(ofd, function (error, stat) { expect(error).not.to.exist; - expect(stat.atime).to.equal(atime); expect(stat.mtime).to.equal(mtime); done(); }); @@ -146,7 +144,6 @@ define(["Filer", "util"], function(Filer, util) { fs.stat('/testdir', function (error, stat) { expect(error).not.to.exist; - expect(stat.atime).to.equal(atime); expect(stat.mtime).to.equal(mtime); done(); }); diff --git a/tests/spec/shell/touch.spec.js b/tests/spec/shell/touch.spec.js index 3b3a12a..224c8e7 100644 --- a/tests/spec/shell/touch.spec.js +++ b/tests/spec/shell/touch.spec.js @@ -92,7 +92,6 @@ define(["Filer", "util"], function(Filer, util) { getTimes(fs, '/newfile', function(times) { expect(times.mtime).to.equal(date); - expect(times.atime).to.equal(date); done(); }); }); From 8c743bb95af5207d706113eca9e894642dbdc8a6 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Wed, 5 Mar 2014 16:27:12 -0500 Subject: [PATCH 10/16] Fix remaining test failures --- src/fs.js | 2 +- tests/spec/adapters/adapters.general.spec.js | 8 +++++++- tests/spec/providers/providers.indexeddb.spec.js | 6 +++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/fs.js b/src/fs.js index 483e806..3406efc 100644 --- a/src/fs.js +++ b/src/fs.js @@ -2465,7 +2465,7 @@ define(function(require) { var fs = this; var error = fs.queueOrRun( function() { - var context = fs.provider.getReadOnlyContext(); + var context = fs.provider.getReadWriteContext(); _exists(context, fs.name, path, callback); } ); diff --git a/tests/spec/adapters/adapters.general.spec.js b/tests/spec/adapters/adapters.general.spec.js index 019434d..068457f 100644 --- a/tests/spec/adapters/adapters.general.spec.js +++ b/tests/spec/adapters/adapters.general.spec.js @@ -131,7 +131,13 @@ define(["Filer", "util"], function(Filer, util) { }); }); - it("should fail when trying to write on ReadOnlyContext", function(done) { + /** + * With issue 123 (see https://github.com/js-platform/filer/issues/128) we had to + * start using readwrite contexts everywhere with IndexedDB. As such, we can't + * easily test this here, without knowing which provider we have. We test this + * in the actual providers, so this isn't really needed. Skipping for now. + */ + it.skip("should fail when trying to write on ReadOnlyContext", function(done) { var provider = createProvider(); provider.open(function(error, firstAccess) { if(error) throw error; diff --git a/tests/spec/providers/providers.indexeddb.spec.js b/tests/spec/providers/providers.indexeddb.spec.js index 6789243..47aec77 100644 --- a/tests/spec/providers/providers.indexeddb.spec.js +++ b/tests/spec/providers/providers.indexeddb.spec.js @@ -129,7 +129,11 @@ define(["Filer", "util"], function(Filer, util) { }); }); - it("should fail when trying to write on ReadOnlyContext", function(done) { + /** + * With issue 123 (see https://github.com/js-platform/filer/issues/128) we had to + * start using readwrite contexts everywhere with IndexedDB. Skipping for now. + */ + it.skip("should fail when trying to write on ReadOnlyContext", function(done) { var provider = _provider.provider; provider.open(function(error, firstAccess) { if(error) throw error; From b95ac40e65950727f63a778600a69116403f8c67 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Wed, 5 Mar 2014 17:00:54 -0500 Subject: [PATCH 11/16] Switch to NOATIME for Filer and mirror ctime to atime. --- src/constants.js | 1 - src/fs.js | 34 ++++++++++------------------------ 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src/constants.js b/src/constants.js index 50b1e2e..56a510a 100644 --- a/src/constants.js +++ b/src/constants.js @@ -58,7 +58,6 @@ define(function(require) { XATTR_CREATE: XATTR_CREATE, XATTR_REPLACE: XATTR_REPLACE, - NOATIME: 'NOATIME', NOCTIME: 'NOCTIME', NOMTIME: 'NOMTIME', diff --git a/src/fs.js b/src/fs.js index 3406efc..b16376a 100644 --- a/src/fs.js +++ b/src/fs.js @@ -52,7 +52,6 @@ define(function(require) { var O_FLAGS = require('src/constants').O_FLAGS; var XATTR_CREATE = require('src/constants').XATTR_CREATE; var XATTR_REPLACE = require('src/constants').XATTR_REPLACE; - var NOATIME = require('src/constants').NOATIME; var NOMTIME = require('src/constants').NOMTIME; var NOCTIME = require('src/constants').NOCTIME; @@ -105,7 +104,7 @@ define(function(require) { this.id = id || guid(); this.mode = mode || MODE_FILE; // node type (file, directory, etc) this.size = size || 0; // size (bytes for files, entries for directories) - this.atime = atime || now; // access time + this.atime = atime || now; // access time (will mirror ctime after creation) this.ctime = ctime || now; // creation/change time this.mtime = mtime || now; // modified time this.flags = flags || []; // file flags @@ -142,9 +141,6 @@ define(function(require) { if(_(flags).contains(NOCTIME)) { delete times.ctime; } - if(_(flags).contains(NOATIME)) { - delete times.atime; - } if(_(flags).contains(NOMTIME)) { delete times.mtime; } @@ -153,9 +149,13 @@ define(function(require) { var update = false; if(times.ctime) { node.ctime = times.ctime; + // We don't do atime tracking for perf reasons, but do mirror ctime + node.atime = times.ctime; update = true; } if(times.atime) { + // The only time we explicitly pass atime is when utimes(), futimes() is called. + // Override ctime mirror here if so node.atime = times.atime; update = true; } @@ -621,9 +621,7 @@ define(function(require) { callback(error); } else { fileNode = result; - update_node_times(context, path, fileNode, { atime: Date.now() }, function(error) { - callback(error, fileNode); - }); + callback(null, fileNode); } } @@ -815,13 +813,7 @@ define(function(require) { callback(error); } else { fileNode = result; - update_node_times(context, ofd.path, fileNode, { atime: Date.now() }, function(error) { - if(error) { - callback(error); - } else { - context.get(fileNode.data, handle_file_data); - } - }); + context.get(fileNode.data, handle_file_data); } } @@ -836,9 +828,7 @@ define(function(require) { if(error) { callback(error); } else { - update_node_times(context, path, result, { atime: Date.now() }, function(error) { - callback(error, result); - }); + callback(null, result); } } @@ -850,9 +840,7 @@ define(function(require) { if(error) { callback(error); } else { - update_node_times(context, ofd.path, result, { atime: Date.now() }, function(error) { - callback(error, result); - }); + callback(null, result); } } @@ -899,9 +887,7 @@ define(function(require) { if(error) { callback(error); } else { - update_node_times(context, path, result, { atime: Date.now() }, function(error) { - callback(error, result); - }); + callback(null, result); } } } From f580f400163adde324125e397929df986f698ccf Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Wed, 5 Mar 2014 19:53:21 -0500 Subject: [PATCH 12/16] Tests for ctime, mtime, atime updates --- tests/spec/times.spec.js | 622 +++++++++++++++++++++++++++++++++++++++ tests/test-manifest.js | 1 + 2 files changed, 623 insertions(+) create mode 100644 tests/spec/times.spec.js diff --git a/tests/spec/times.spec.js b/tests/spec/times.spec.js new file mode 100644 index 0000000..835b005 --- /dev/null +++ b/tests/spec/times.spec.js @@ -0,0 +1,622 @@ +define(["Filer", "util"], function(Filer, util) { + + describe('node times (atime, mtime, ctime)', function() { + beforeEach(util.setup); + afterEach(util.cleanup); + + var dirname = "/dir"; + var filename = "/dir/file"; + + function createTree(callback) { + var fs = util.fs(); + fs.mkdir(dirname, function(error) { + if(error) throw error; + + fs.open(filename, 'w', function(error, fd) { + if(error) throw error; + + fs.close(fd, callback); + }); + }); + } + + function stat(path, callback) { + var fs = util.fs(); + fs.stat(path, function(error, stats) { + if(error) throw error; + + callback(stats); + }); + } + + it('should update ctime when calling fs.rename()', function(done) { + var fs = util.fs(); + var newfilename = filename + '1'; + + createTree(function() { + stat(filename, function(stats1) { + + fs.rename(filename, newfilename, function(error) { + if(error) throw error; + + stat(newfilename, function(stats2) { + expect(stats2.ctime).to.be.above(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.be.above(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should update ctime, mtime, atime when calling fs.truncate()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + + fs.truncate(filename, 5, function(error) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.be.above(stats1.ctime); + expect(stats2.mtime).to.be.above(stats1.mtime); + expect(stats2.atime).to.be.above(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should update ctime, mtime, atime when calling fs.ftruncate()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + + fs.open(filename, 'w', function(error, fd) { + if(error) throw error; + + fs.ftruncate(fd, 5, function(error) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.be.above(stats1.ctime); + expect(stats2.mtime).to.be.above(stats1.mtime); + expect(stats2.atime).to.be.above(stats1.atime); + + fs.close(fd, done); + }); + }); + }); + }); + }); + }); + + it('should make no change when calling fs.stat()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + + fs.stat(filename, function(error, stats2) { + if(error) throw error; + + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); + }); + }); + }); + }); + + it('should make no change when calling fs.fstat()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + + fs.open(filename, 'w', function(error, fd) { + if(error) throw error; + + fs.fstat(fd, function(error, stats2) { + if(error) throw error; + + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + + fs.close(fd, done); + }); + }); + }); + }); + }); + + it('should make no change when calling fs.lstat()', function(done) { + var fs = util.fs(); + + createTree(function() { + fs.link(filename, '/link', function(error) { + if(error) throw error; + + stat(filename, function(stats1) { + fs.lstat('/link', function(error, stats2) { + if(error) throw error; + + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should make no change when calling fs.exists()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + + fs.exists(filename, function(exists) { + expect(exists).to.be.true; + + fs.stat(filename, function(error, stats2) { + if(error) throw error; + + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should update ctime, atime when calling fs.link()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + fs.link(filename, '/link', function(error) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.be.above(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.be.above(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should make no change when calling fs.symlink()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + fs.symlink(filename, '/link', function(error) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should make no change when calling fs.readlink()', function(done) { + var fs = util.fs(); + + createTree(function() { + fs.symlink(filename, '/link', function(error) { + if(error) throw error; + + stat('/link', function(stats1) { + fs.readlink('/link', function(error, contents) { + if(error) throw error; + expect(contents).to.equal(filename); + + stat('/link', function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); + }); + }); + }); + }); + }); + }); + + it('should update ctime, atime, mtime of parent dir when calling fs.unlink()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(dirname, function(stats1) { + fs.unlink(filename, function(error) { + if(error) throw error; + + stat(dirname, function(stats2) { + expect(stats2.ctime).to.be.above(stats1.ctime); + expect(stats2.mtime).to.be.above(stats1.mtime); + expect(stats2.atime).to.be.above(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should update ctime, atime, mtime of parent dir when calling fs.rmdir()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat('/', function(stats1) { + + fs.unlink(filename, function(error) { + if(error) throw error; + + fs.rmdir(dirname, function(error) { + if(error) throw error; + + stat('/', function(stats2) { + expect(stats2.ctime).to.be.above(stats1.ctime); + expect(stats2.mtime).to.be.above(stats1.mtime); + expect(stats2.atime).to.be.above(stats1.atime); + done(); + }); + }); + }); + }); + }); + }); + + it('should update ctime, atime, mtime of parent dir when calling fs.mkdir()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat('/', function(stats1) { + + fs.mkdir('/a', function(error) { + if(error) throw error; + + stat('/', function(stats2) { + expect(stats2.ctime).to.be.above(stats1.ctime); + expect(stats2.mtime).to.be.above(stats1.mtime); + expect(stats2.atime).to.be.above(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should make no change when calling fs.close()', function(done) { + var fs = util.fs(); + + createTree(function() { + fs.open(filename, 'w', function(error, fd) { + if(error) throw error; + + stat(filename, function(stats1) { + fs.close(fd, function(error) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); + }); + }); + }); + }); + }); + }); + + it('should make no change when calling fs.open()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + fs.open(filename, 'w', function(error, fd) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + + fs.close(fd, done); + }); + }); + }); + }); + }); + + /** + * fs.utimes and fs.futimes are tested elsewhere already, skipping + */ + + it('should update atime, ctime, mtime when calling fs.write()', function(done) { + var fs = util.fs(); + var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + + createTree(function() { + fs.open('/myfile', 'w', function(err, fd) { + if(err) throw error; + + stat('/myfile', function(stats1) { + fs.write(fd, buffer, 0, buffer.length, 0, function(err, nbytes) { + if(err) throw error; + + fs.close(fd, function(error) { + if(error) throw error; + + stat('/myfile', function(stats2) { + expect(stats2.ctime).to.be.above(stats1.ctime); + expect(stats2.mtime).to.be.above(stats1.mtime); + expect(stats2.atime).to.be.above(stats1.atime); + done(); + }); + }); + }); + }); + }); + }); + }); + + it('should make no change when calling fs.read()', function(done) { + var fs = util.fs(); + var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + + createTree(function() { + fs.open('/myfile', 'w', function(err, fd) { + if(err) throw err; + + fs.write(fd, buffer, 0, buffer.length, 0, function(err, nbytes) { + if(err) throw err; + + fs.close(fd, function(error) { + if(error) throw error; + + fs.open('/myfile', 'r', function(error, fd) { + if(error) throw error; + + stat('/myfile', function(stats1) { + var buffer2 = new Uint8Array(buffer.length); + fs.read(fd, buffer2, 0, buffer2.length, 0, function(err, nbytes) { + + fs.close(fd, function(error) { + if(error) throw error; + + stat('/myfile', function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); + }); + }); + }); + }); + }); + }); + }); + }); + }); + }); + + it('should make no change when calling fs.readFile()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + fs.readFile(filename, function(error, data) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should update atime, ctime, mtime when calling fs.writeFile()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + fs.writeFile(filename, 'data', function(error) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.be.above(stats1.ctime); + expect(stats2.mtime).to.be.above(stats1.mtime); + expect(stats2.atime).to.be.above(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should update atime, ctime, mtime when calling fs.appendFile()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + fs.appendFile(filename, '...more data', function(error) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.be.above(stats1.ctime); + expect(stats2.mtime).to.be.above(stats1.mtime); + expect(stats2.atime).to.be.above(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should update ctime, atime when calling fs.setxattr()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + fs.setxattr(filename, 'extra', 'data', function(error) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.be.above(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.be.above(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should update ctime, atime when calling fs.fsetxattr()', function(done) { + var fs = util.fs(); + + createTree(function() { + fs.open(filename, 'w', function(error, fd) { + if(error) throw error; + + stat(filename, function(stats1) { + fs.fsetxattr(fd, 'extra', 'data', function(error) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.be.above(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.be.above(stats1.atime); + done(); + }); + }); + }); + }); + }); + }); + + it('should make no change when calling fs.getxattr()', function(done) { + var fs = util.fs(); + + createTree(function() { + fs.setxattr(filename, 'extra', 'data', function(error) { + if(error) throw error; + + stat(filename, function(stats1) { + fs.getxattr(filename, 'extra', function(error, value) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); + }); + }); + }); + }); + }); + }); + + it('should make no change when calling fs.fgetxattr()', function(done) { + var fs = util.fs(); + + createTree(function() { + fs.open(filename, 'w', function(error, fd) { + if(error) throw error; + + fs.fsetxattr(fd, 'extra', 'data', function(error) { + if(error) throw error; + + stat(filename, function(stats1) { + fs.fgetxattr(fd, 'extra', function(error, value) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); + }); + }); + }); + }); + }); + }); + }); + + it('should update ctime, atime when calling fs.removexattr()', function(done) { + var fs = util.fs(); + + createTree(function() { + fs.setxattr(filename, 'extra', 'data', function(error) { + if(error) throw error; + + stat(filename, function(stats1) { + fs.removexattr(filename, 'extra', function(error) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.be.above(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.be.above(stats1.atime); + done(); + }); + }); + }); + }); + }); + }); + + it('should update ctime, atime when calling fs.fremovexattr()', function(done) { + var fs = util.fs(); + + createTree(function() { + fs.open(filename, 'w', function(error, fd) { + if(error) throw error; + + fs.fsetxattr(fd, 'extra', 'data', function(error) { + if(error) throw error; + + stat(filename, function(stats1) { + fs.fremovexattr(fd, 'extra', function(error) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.be.above(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.be.above(stats1.atime); + done(); + }); + }); + }); + }); + }); + }); + }); + + }); +}); diff --git a/tests/test-manifest.js b/tests/test-manifest.js index 026c4b7..a8ed712 100644 --- a/tests/test-manifest.js +++ b/tests/test-manifest.js @@ -32,6 +32,7 @@ define([ "spec/fs.utimes.spec", "spec/fs.xattr.spec", "spec/path-resolution.spec", + "spec/times.spec", // Filer.FileSystem.providers.* "spec/providers/providers.spec", From 5438d8c97b262936eb689cc51990d244560179dd Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Wed, 5 Mar 2014 20:03:27 -0500 Subject: [PATCH 13/16] Fix mount flags per review and also write docs --- README.md | 7 +++++-- src/constants.js | 7 ++++--- src/fs.js | 8 ++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index fc130e2..877cb4e 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,10 @@ Accepts two arguments: an `options` object, and an optional `callback`. The `opt object can specify a number of optional arguments, including: * `name`: the name of the file system, defaults to `'"local'` -* `flags`: one or more flags to use when creating/opening the file system. Use `'FORMAT'` to force Filer to format (i.e., erase) the file system +* `flags`: an Array of one or more flags to use when creating/opening the file system: + *`'FORMAT'` to force Filer to format (i.e., erase) the file system + *`'NOCTIME'` to force Filer to not update `ctime` on nodes when metadata changes (i.e., for better performance) + *`'NOMTIME'` to force Filer to not update `mtime` on nodes when data changes (i.e., for better performance) * `provider`: an explicit storage provider to use for the file system's database context provider. See the section on [Storage Providers](#providers). The `callback` function indicates when the file system is ready for use. Depending on the storage provider used, this might @@ -98,7 +101,7 @@ function fsReady(err, fs) { fs = new Filer.FileSystem({ name: "my-filesystem", - flags: 'FORMAT', + flags: [ 'FORMAT' ], provider: new Filer.FileSystem.providers.Memory() }, fsReady); ``` diff --git a/src/constants.js b/src/constants.js index 56a510a..660810f 100644 --- a/src/constants.js +++ b/src/constants.js @@ -33,8 +33,12 @@ define(function(require) { ROOT_DIRECTORY_NAME: '/', // basename(normalize(path)) + // FS Mount Flags FS_FORMAT: 'FORMAT', + FS_NOCTIME: 'NOCTIME', + FS_NOMTIME: 'NOMTIME', + // FS File Open Flags O_READ: O_READ, O_WRITE: O_WRITE, O_CREATE: O_CREATE, @@ -58,9 +62,6 @@ define(function(require) { XATTR_CREATE: XATTR_CREATE, XATTR_REPLACE: XATTR_REPLACE, - NOCTIME: 'NOCTIME', - NOMTIME: 'NOMTIME', - FS_READY: 'READY', FS_PENDING: 'PENDING', FS_ERROR: 'ERROR', diff --git a/src/fs.js b/src/fs.js index b16376a..b5662eb 100644 --- a/src/fs.js +++ b/src/fs.js @@ -52,8 +52,8 @@ define(function(require) { var O_FLAGS = require('src/constants').O_FLAGS; var XATTR_CREATE = require('src/constants').XATTR_CREATE; var XATTR_REPLACE = require('src/constants').XATTR_REPLACE; - var NOMTIME = require('src/constants').NOMTIME; - var NOCTIME = require('src/constants').NOCTIME; + var FS_NOMTIME = require('src/constants').FS_NOMTIME; + var FS_NOCTIME = require('src/constants').FS_NOCTIME; var providers = require('src/providers/providers'); var adapters = require('src/adapters/adapters'); @@ -138,10 +138,10 @@ define(function(require) { function update_node_times(context, path, node, times, callback) { // Honour mount flags for how we update times var flags = context.flags; - if(_(flags).contains(NOCTIME)) { + if(_(flags).contains(FS_NOCTIME)) { delete times.ctime; } - if(_(flags).contains(NOMTIME)) { + if(_(flags).contains(FS_NOMTIME)) { delete times.mtime; } From 72e527dfabc699bfb272289f52009f5b5b244d53 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Wed, 5 Mar 2014 21:41:45 -0500 Subject: [PATCH 14/16] Add tests for time mount flag suppression (NOMTIME, NOCTIME) --- tests/spec/time-flags.spec.js | 106 ++++++++++++++++++++++++++++++++++ tests/test-manifest.js | 1 + 2 files changed, 107 insertions(+) create mode 100644 tests/spec/time-flags.spec.js diff --git a/tests/spec/time-flags.spec.js b/tests/spec/time-flags.spec.js new file mode 100644 index 0000000..49b17a4 --- /dev/null +++ b/tests/spec/time-flags.spec.js @@ -0,0 +1,106 @@ +define(["Filer", "util"], function(Filer, util) { + + describe('node times (atime, mtime, ctime) with mount flags', function() { + + var dirname = "/dir"; + var filename = "/dir/file"; + + function memoryFS(flags, callback) { + var name = util.uniqueName(); + var fs = new Filer.FileSystem({ + name: name, + flags: flags || [], + provider: new Filer.FileSystem.providers.Memory(name) + }, callback); + } + + function createTree(fs, callback) { + fs.mkdir(dirname, function(error) { + if(error) throw error; + + fs.open(filename, 'w', function(error, fd) { + if(error) throw error; + + fs.close(fd, callback); + }); + }); + } + + function stat(fs, path, callback) { + fs.stat(path, function(error, stats) { + if(error) throw error; + + callback(stats); + }); + } + + /** + * We test the actual time updates in times.spec.js, whereas these just test + * the overrides with the mount flags. The particular fs methods called + * are unimportant, but are known to affect the particular times being suppressed. + */ + + it('should not update ctime when calling fs.rename() with NOCTIME', function(done) { + memoryFS(['NOCTIME'], function(error, fs) { + var newfilename = filename + '1'; + + createTree(fs, function() { + stat(fs, filename, function(stats1) { + + fs.rename(filename, newfilename, function(error) { + if(error) throw error; + + stat(fs, newfilename, function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); + }); + }); + }); + }); + }); + }); + + it('should not update ctime, mtime, atime when calling fs.truncate() with NOCTIME, NOMTIME', function(done) { + memoryFS(['NOCTIME', 'NOMTIME'], function(error, fs) { + createTree(fs, function() { + stat(fs, filename, function(stats1) { + + fs.truncate(filename, 5, function(error) { + if(error) throw error; + + stat(fs, filename, function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); + }); + }); + }); + }); + }); + }); + + it('should not update mtime when calling fs.truncate() with NOMTIME', function(done) { + memoryFS(['NOMTIME'], function(error, fs) { + createTree(fs, function() { + stat(fs, filename, function(stats1) { + + fs.truncate(filename, 5, function(error) { + if(error) throw error; + + stat(fs, filename, function(stats2) { + expect(stats2.ctime).to.be.above(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.be.above(stats1.atime); + done(); + }); + }); + }); + }); + }); + }); + + }); +}); diff --git a/tests/test-manifest.js b/tests/test-manifest.js index a8ed712..688d231 100644 --- a/tests/test-manifest.js +++ b/tests/test-manifest.js @@ -33,6 +33,7 @@ define([ "spec/fs.xattr.spec", "spec/path-resolution.spec", "spec/times.spec", + "spec/time-flags.spec", // Filer.FileSystem.providers.* "spec/providers/providers.spec", From 31ef56ff8e713440807ad1b3c1dafa427dfd213f Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Wed, 5 Mar 2014 22:02:05 -0500 Subject: [PATCH 15/16] Increase the test timeout threshold from 2s to 5s (for longer db operations), with a slow test warning of 250ms --- tests/require-config.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/require-config.js b/tests/require-config.js index 5dfdeb7..2415177 100644 --- a/tests/require-config.js +++ b/tests/require-config.js @@ -78,8 +78,9 @@ require.config(config); assert = chai.assert; expect = chai.expect; -// We need to setup describe() support before loading tests -mocha.setup("bdd"); +// We need to setup describe() support before loading tests. +// Use a test timeout of 5s and a slow-test warning of 250ms +mocha.setup("bdd").timeout(5000).slow(250); require(["tests/test-manifest"], function() { window.onload = function() { From bb9c34e5b30ad7a0da104e1a6e54448d7e9dec57 Mon Sep 17 00:00:00 2001 From: Alan Kligman Date: Thu, 6 Mar 2014 11:35:53 -0500 Subject: [PATCH 16/16] Revert "Merge pull request #113 from kwkofler/issue#112" This reverts commit bfba8c3546fcb9135eed4b8e428cfce5e3366c1a, reversing changes made to f079eaa7dddc4242a06d61fe4cbd1ac2992c5ba2. --- src/fs.js | 28 ---- tests/spec/fs.Stats.spec.js | 306 ------------------------------------ tests/test-manifest.js | 1 - 3 files changed, 335 deletions(-) delete mode 100644 tests/spec/fs.Stats.spec.js diff --git a/src/fs.js b/src/fs.js index 41d1da2..b5662eb 100644 --- a/src/fs.js +++ b/src/fs.js @@ -131,34 +131,6 @@ define(function(require) { this.type = fileNode.mode; } - Stats.prototype.isFile = function() { - return this.type === constants.MODE_FILE; - }; - - Stats.prototype.isDirectory = function() { - return this.type === constants.MODE_DIRECTORY; - }; - - Stats.prototype.isBlockDevice = function() { - return false; - }; - - Stats.prototype.isCharacterDevice = function() { - return false; - }; - - Stats.prototype.isSymbolicLink = function() { - return this.type === constants.MODE_SYMBOLIC_LINK; - }; - - Stats.prototype.isFIFO = function() { - return false; - }; - - Stats.prototype.isSocket = function() { - return false; - }; - /* * Update node times. Only passed times are modified (undefined times are ignored) * and filesystem flags are examined in order to override update logic. diff --git a/tests/spec/fs.Stats.spec.js b/tests/spec/fs.Stats.spec.js deleted file mode 100644 index 09d9c08..0000000 --- a/tests/spec/fs.Stats.spec.js +++ /dev/null @@ -1,306 +0,0 @@ -define(["Filer"], function(Filer) { - - describe('fs.Stats', function() { - describe('#isFile()', function() { - beforeEach(function() { - this.db_name = mk_db_name(); - this.fs = new Filer.FileSystem({ - name: this.db_name, - flags: 'FORMAT' - }); - }); - - afterEach(function() { - indexedDB.deleteDatabase(this.db_name); - delete this.fs; - }); - - it('should be a function', function() { - var testStat = this.fs.stat('/', function(error) { - if(error) throw error; - }); - expect(typeof this.testStat.isFile).toEqual('function'); - }); - - it('should return true if stats are for file', function() { - var complete = false; - var _error, _result; - var that = this; - - var contents = "This is a file."; - - that.fs.writeFile('/myFile', contents, binary, function(error) { - if(error) throw error; - _result = that.fs.stat('/myFile', function() {}).isFile(); - complete = true; - }) - - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function() { - expect(_error).toEqual(null); - expect(_result).toEqual(true); - }); - }); - }) - - describe('#isDirectory()', function() { - beforeEach(function() { - this.db_name = mk_db_name(); - this.fs = new Filer.FileSystem({ - name: this.db_name, - flags: 'FORMAT' - }); - }); - - afterEach(function() { - indexedDB.deleteDatabase(this.db_name); - delete this.fs; - }); - - it('should be a function', function() { - var testStat = this.fs.stat('/', function(error) { - if(error) throw error; - }); - expect(typeof this.testStat.isDirectory).toEqual('function'); - }); - - it('should only return true if stats are for directory', function() { - var complete = false; - var _result; - var that = this; - - _result = that.fs.stat('/myFile', function(error) { - if(error) throw error; - }).isFile(); - complete = true; - - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function() { - expect(_error).toEqual(null); - expect(_result).toEqual(true); - }); - }); - }) - - describe('#isBlockDevice()', function() { - beforeEach(function() { - this.db_name = mk_db_name(); - this.fs = new Filer.FileSystem({ - name: this.db_name, - flags: 'FORMAT' - }); - }); - - afterEach(function() { - indexedDB.deleteDatabase(this.db_name); - delete this.fs; - }); - - it('should be a function', function() { - var testStat = this.fs.stat('/', function(error) { - if(error) throw error; - }); - expect(typeof this.testStat.isBlockDevice).toEqual('function'); - }); - - it('should return false', function() { - var complete = false; - var _result; - var that = this; - - _result = that.fs.stat('/', function(error) { - if(error) throw error; - }).isBlockDevice(); - complete = true; - - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function() { - expect(_error).toEqual(null); - expect(_result).toEqual(false); - }); - }); - }) - - describe('#isCharacterDevice()', function() { - beforeEach(function() { - this.db_name = mk_db_name(); - this.fs = new Filer.FileSystem({ - name: this.db_name, - flags: 'FORMAT' - }); - }); - - afterEach(function() { - indexedDB.deleteDatabase(this.db_name); - delete this.fs; - }); - - it('should be a function', function() { - var testStat = this.fs.stat('/', function(error) { - if(error) throw error; - }); - expect(typeof this.testStat.isCharacterDevice).toEqual('function'); - }); - - it('should return false', function() { - var complete = false; - var _result; - var that = this; - - _result = that.fs.stat('/', function(error) { - if(error) throw error; - }).isCharacterDevice(); - complete = true; - - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function() { - expect(_error).toEqual(null); - expect(_result).toEqual(false); - }); - }); - }) - - describe('#isSymbolicLink()', function() { - beforeEach(function() { - this.db_name = mk_db_name(); - this.fs = new Filer.FileSystem({ - name: this.db_name, - flags: 'FORMAT' - }); - }); - - afterEach(function() { - indexedDB.deleteDatabase(this.db_name); - delete this.fs; - }); - - it('should be a function', function() { - var testStat = this.fs.stat('/', function(error) { - if(error) throw error; - }); - expect(typeof this.testStat.isSymbolicLink).toEqual('function'); - }); - - it('should return true if stats are for symbolic link', function() { - var complete = false; - var _error, _result; - var that = this; - - that.fs.writeFile('/myfile', '', { encoding: 'utf8' }, function(error) { - if(error) throw error; - that.fs.symlink('/myfile', '/myFileLink', function (error) { - if (error) throw error; - _result = that.fs.lstat('/myfile', function(error) { - if(error) throw error; - }).isSymbolicLink(); - complete = true; - }); - }); - - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function() { - expect(_error).toEqual(null); - expect(_result).toEqual(true); - }); - }); - }) - - describe('#isFIFO()', function() { - beforeEach(function() { - this.db_name = mk_db_name(); - this.fs = new Filer.FileSystem({ - name: this.db_name, - flags: 'FORMAT' - }); - }); - - afterEach(function() { - indexedDB.deleteDatabase(this.db_name); - delete this.fs; - }); - - it('should be a function', function() { - var testStat = this.fs.stat('/', function(error) { - if(error) throw error; - }); - expect(typeof this.testStat.isFIFO).toEqual('function'); - }); - - it('should return false', function() { - var complete = false; - var _result; - var that = this; - - _result = that.fs.stat('/', function(error) { - if(error) throw error; - }).isFIFO(); - complete = true; - - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function() { - expect(_error).toEqual(null); - expect(_result).toEqual(false); - }); - }); - }) - - describe('#isSocket()', function() { - beforeEach(function() { - this.db_name = mk_db_name(); - this.fs = new Filer.FileSystem({ - name: this.db_name, - flags: 'FORMAT' - }); - }); - - afterEach(function() { - indexedDB.deleteDatabase(this.db_name); - delete this.fs; - }); - - it('should be a function', function() { - var testStat = this.fs.stat('/', function(error) { - if(error) throw error; - }); - expect(typeof this.testStat.isSocket).toEqual('function'); - }); - - it('should return false', function() { - var complete = false; - var _result; - var that = this; - - _result = that.fs.stat('/', function(error) { - if(error) throw error; - }).isSocket(); - complete = true; - - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function() { - expect(_error).toEqual(null); - expect(_result).toEqual(false); - }); - }); - }) - } \ No newline at end of file diff --git a/tests/test-manifest.js b/tests/test-manifest.js index ad060a7..688d231 100644 --- a/tests/test-manifest.js +++ b/tests/test-manifest.js @@ -31,7 +31,6 @@ define([ "spec/fs.truncate.spec", "spec/fs.utimes.spec", "spec/fs.xattr.spec", - "spec/fs.stats.spec". "spec/path-resolution.spec", "spec/times.spec", "spec/time-flags.spec",