Get rid of data/fsUtils

This commit is contained in:
Juan Cruz Viotti 2014-12-09 09:05:37 -04:00
parent d62248b6d3
commit f658fab566
36 changed files with 450 additions and 161 deletions

View File

@ -43,6 +43,16 @@
InvalidCredentials
</a>
</li>
<li>
<a href='class/InvalidKey.html'>
InvalidKey
</a>
</li>
<li>
<a href='class/InvalidPath.html'>
InvalidPath
</a>
</li>
</ul>
</ul>
<ul>
@ -155,19 +165,6 @@
</li>
</ul>
</ul>
<ul>
<li class='letter'>f</li>
<ul>
<li>
<a href='file/lib/resin/data/fs-utils/fs-utils.coffee.html'>
fs-utils.coffee
</a>
<small>
(lib&#47;resin&#47;data&#47;fs-utils)
</small>
</li>
</ul>
</ul>
<ul>
<li class='letter'>h</li>
<ul>
@ -266,7 +263,7 @@
</div>
</div>
<div id='footer'>
December 09, 14 08:42:53 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -87,7 +87,7 @@
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -83,7 +83,7 @@ Error: Invalid configuration file: /opt/resin.conf
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -70,7 +70,7 @@ Error: Invalid credentials
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

144
doc/class/InvalidKey.html Normal file
View File

@ -0,0 +1,144 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>CoffeeScript API Documentation</title>
<script src='../javascript/application.js'></script>
<script src='../javascript/search.js'></script>
<link rel='stylesheet' href='../stylesheets/application.css' type='text/css'>
</head>
<body>
<div id='base' data-path='../'></div>
<div id='header'>
<div id='menu'>
<a href='../alphabetical_index.html' title='Index'>
Index
</a>
&raquo;
<span class='title'>InvalidKey</span>
</div>
</div>
<div id='content'>
<h1>
Class:
InvalidKey
</h1>
<table class='box'>
<tr>
<td>Defined in:</td>
<td>lib&#47;resin&#47;errors&#47;errors.coffee</td>
</tr>
<tr>
<td>Inherits:</td>
<td>
TypedError
</td>
</tr>
</table>
<h2>Variables Summary</h2>
<dl class='constants'>
<dt id='code-variable'>
code
=
</dt>
<dd>
<pre><code class='coffeescript'>1</code></pre>
<div class='docstring'>
<p>Error code</p>
</div>
<div class='tags'>
</div>
</dd>
</dl>
<h2>Constructor Details</h2>
<div class='methods'>
<div class='method_details'>
<p class='signature' id='constructor-dynamic'>
#
(void)
<b>constructor</b><span>()</span>
<br>
</p>
<div class='docstring'>
<p>Construct an Invalid Key error</p><pre><code>throw new resin.errors.InvalidKey()
Error: Invalid key
</code></pre>
</div>
<div class='tags'>
</div>
</div>
</div>
</div>
<div id='footer'>
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>
2.0.9
&#10034;
Press H to see the keyboard shortcuts
&#10034;
<a href='http://twitter.com/netzpirat' target='_parent'>@netzpirat</a>
&#10034;
<a href='http://twitter.com/_inossidabile' target='_parent'>@_inossidabile</a>
</div>
<iframe id='search_frame'></iframe>
<div id='fuzzySearch'>
<input type='text'>
<ol></ol>
</div>
<div id='help'>
<p>
Quickly fuzzy find classes, mixins, methods, file:
</p>
<ul>
<li>
<span>T</span>
Open fuzzy finder dialog
</li>
</ul>
<p>
Control the navigation frame:
</p>
<ul>
<li>
<span>L</span>
Toggle list view
</li>
<li>
<span>C</span>
Show class list
</li>
<li>
<span>I</span>
Show mixin list
</li>
<li>
<span>F</span>
Show file list
</li>
<li>
<span>M</span>
Show method list
</li>
<li>
<span>E</span>
Show extras list
</li>
</ul>
<p>
You can focus and blur the search input:
</p>
<ul>
<li>
<span>S</span>
Focus search input
</li>
<li>
<span>Esc</span>
Blur search input
</li>
</ul>
</div>
</body>
</html>

157
doc/class/InvalidPath.html Normal file
View File

@ -0,0 +1,157 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>CoffeeScript API Documentation</title>
<script src='../javascript/application.js'></script>
<script src='../javascript/search.js'></script>
<link rel='stylesheet' href='../stylesheets/application.css' type='text/css'>
</head>
<body>
<div id='base' data-path='../'></div>
<div id='header'>
<div id='menu'>
<a href='../alphabetical_index.html' title='Index'>
Index
</a>
&raquo;
<span class='title'>InvalidPath</span>
</div>
</div>
<div id='content'>
<h1>
Class:
InvalidPath
</h1>
<table class='box'>
<tr>
<td>Defined in:</td>
<td>lib&#47;resin&#47;errors&#47;errors.coffee</td>
</tr>
<tr>
<td>Inherits:</td>
<td>
TypedError
</td>
</tr>
</table>
<h2>Variables Summary</h2>
<dl class='constants'>
<dt id='code-variable'>
code
=
</dt>
<dd>
<pre><code class='coffeescript'>1</code></pre>
<div class='docstring'>
<p>Error code</p>
</div>
<div class='tags'>
</div>
</dd>
</dl>
<h2>Constructor Details</h2>
<div class='methods'>
<div class='method_details'>
<p class='signature' id='constructor-dynamic'>
#
(void)
<b>constructor</b><span>(path)</span>
<br>
</p>
<div class='docstring'>
<p>Construct an Invalid Path error</p><pre><code>throw new resin.errors.InvalidPath(&#39;/tmp&#39;)
Error: Invalid path: /tmp
</code></pre>
</div>
<div class='tags'>
<h3>Parameters:</h3>
<ul class='param'>
<li>
<span class='name'>path</span>
<span class='type'>
(
<tt>String</tt>
)
</span>
&mdash;
<span class='desc'>the name of the invalid path </span>
</li>
</ul>
</div>
</div>
</div>
</div>
<div id='footer'>
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>
2.0.9
&#10034;
Press H to see the keyboard shortcuts
&#10034;
<a href='http://twitter.com/netzpirat' target='_parent'>@netzpirat</a>
&#10034;
<a href='http://twitter.com/_inossidabile' target='_parent'>@_inossidabile</a>
</div>
<iframe id='search_frame'></iframe>
<div id='fuzzySearch'>
<input type='text'>
<ol></ol>
</div>
<div id='help'>
<p>
Quickly fuzzy find classes, mixins, methods, file:
</p>
<ul>
<li>
<span>T</span>
Open fuzzy finder dialog
</li>
</ul>
<p>
Control the navigation frame:
</p>
<ul>
<li>
<span>L</span>
Toggle list view
</li>
<li>
<span>C</span>
Show class list
</li>
<li>
<span>I</span>
Show mixin list
</li>
<li>
<span>F</span>
Show file list
</li>
<li>
<span>M</span>
Show method list
</li>
<li>
<span>E</span>
Show extras list
</li>
</ul>
<p>
You can focus and blur the search input:
</p>
<ul>
<li>
<span>S</span>
Focus search input
</li>
<li>
<span>Esc</span>
Blur search input
</li>
</ul>
</div>
</body>
</html>

View File

@ -83,7 +83,7 @@ Error: You don&#39;t have any applications
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -83,7 +83,7 @@ Error: Couldn&#39;t find application
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -62,6 +62,30 @@
</small>
</li>
<li>
<a href='class/InvalidKey.html' target='main'>
InvalidKey
</a>
<small class='parent'>
<
TypedError
</small>
<small class='namespace'>
</small>
</li>
<li>
<a href='class/InvalidPath.html' target='main'>
InvalidPath
</a>
<small class='parent'>
<
TypedError
</small>
<small class='namespace'>
</small>
</li>
<li>
<a href='class/NotAny.html' target='main'>
NotAny

View File

@ -392,7 +392,7 @@
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -119,7 +119,7 @@ console.log(contents.remoteUrl)
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -169,7 +169,7 @@
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -37,7 +37,7 @@
</table>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -186,7 +186,7 @@ console.log(devices)
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -94,7 +94,7 @@ resin.errors.handle(error, shouldExit)
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -105,7 +105,7 @@ console.log(object.dataPrefix) # /opt/resin
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -57,7 +57,7 @@
</dl>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -348,7 +348,7 @@
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -47,7 +47,7 @@
</table>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -326,7 +326,7 @@
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -316,7 +316,7 @@
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -154,7 +154,7 @@
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -52,7 +52,7 @@
</dl>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -156,7 +156,7 @@ console.log(result)
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -227,7 +227,7 @@ resin.server.request { method: &#39;GET&#39; url: &#39;/download&#39; p
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -77,7 +77,7 @@
</dl>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -235,7 +235,7 @@
</div>
</div>
<div id='footer'>
December 09, 14 08:42:54 by
December 09, 14 09:05:26 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -92,22 +92,6 @@
lib&#47;resin&#47;data
</small>
</li>
<li>
<span>
fs-utils
</span>
</li>
<ul>
<li>
<a href='file/lib/resin/data/fs-utils/fs-utils.coffee.html' target='main'>
fs-utils.coffee
</a>
<small class='namespace'>
lib&#47;resin&#47;data&#47;fs-utils
</small>
</li>
</ul>
</ul>
<li>

File diff suppressed because one or more lines are too long

View File

@ -75,11 +75,27 @@
</small>
</li>
<li>
<a href='class/InvalidCredentials.html#constructor-dynamic' target='main' title='constructor'>
<a href='class/InvalidPath.html#constructor-dynamic' target='main' title='constructor'>
#constructor
</a>
<small>
(InvalidCredentials)
(InvalidPath)
</small>
</li>
<li>
<a href='class/InvalidKey.html#constructor-dynamic' target='main' title='constructor'>
#constructor
</a>
<small>
(InvalidKey)
</small>
</li>
<li>
<a href='class/NotAny.html#constructor-dynamic' target='main' title='constructor'>
#constructor
</a>
<small>
(NotAny)
</small>
</li>
<li>
@ -91,11 +107,11 @@
</small>
</li>
<li>
<a href='class/NotAny.html#constructor-dynamic' target='main' title='constructor'>
<a href='class/InvalidCredentials.html#constructor-dynamic' target='main' title='constructor'>
#constructor
</a>
<small>
(NotAny)
(InvalidCredentials)
</small>
</li>
<li>
@ -130,14 +146,6 @@
(lib&#47;resin&#47;os&#47;os.coffee)
</small>
</li>
<li>
<a href='file/lib/resin/data/data-prefix.coffee.html#get-' target='main' title='get'>
~get
</a>
<small>
(lib&#47;resin&#47;data&#47;data-prefix.coffee)
</small>
</li>
<li>
<a href='file/lib/resin/models/device.coffee.html#get-' target='main' title='get'>
~get
@ -146,6 +154,14 @@
(lib&#47;resin&#47;models&#47;device.coffee)
</small>
</li>
<li>
<a href='file/lib/resin/data/data-prefix.coffee.html#get-' target='main' title='get'>
~get
</a>
<small>
(lib&#47;resin&#47;data&#47;data-prefix.coffee)
</small>
</li>
<li>
<a href='file/lib/resin/models/application.coffee.html#get-' target='main' title='get'>
~get
@ -154,14 +170,6 @@
(lib&#47;resin&#47;models&#47;application.coffee)
</small>
</li>
<li>
<a href='file/lib/resin/models/application.coffee.html#getAll-' target='main' title='getAll'>
~getAll
</a>
<small>
(lib&#47;resin&#47;models&#47;application.coffee)
</small>
</li>
<li>
<a href='file/lib/resin/models/device.coffee.html#getAll-' target='main' title='getAll'>
~getAll
@ -170,6 +178,14 @@
(lib&#47;resin&#47;models&#47;device.coffee)
</small>
</li>
<li>
<a href='file/lib/resin/models/application.coffee.html#getAll-' target='main' title='getAll'>
~getAll
</a>
<small>
(lib&#47;resin&#47;models&#47;application.coffee)
</small>
</li>
<li>
<a href='file/lib/resin/models/environment-variables.coffee.html#getAllByApplication-' target='main' title='getAllByApplication'>
~getAllByApplication
@ -274,14 +290,6 @@
(lib&#47;resin&#47;log&#47;log.coffee)
</small>
</li>
<li>
<a href='file/lib/resin/data/fs-utils/fs-utils.coffee.html#isValidPath-' target='main' title='isValidPath'>
~isValidPath
</a>
<small>
(lib&#47;resin&#47;data&#47;fs-utils&#47;fs-utils.coffee)
</small>
</li>
<li>
<a href='file/lib/resin/config/config.coffee.html#loadUserConfig-' target='main' title='loadUserConfig'>
~loadUserConfig
@ -331,11 +339,11 @@
</small>
</li>
<li>
<a href='file/lib/resin/models/device.coffee.html#remove-' target='main' title='remove'>
<a href='file/lib/resin/models/environment-variables.coffee.html#remove-' target='main' title='remove'>
~remove
</a>
<small>
(lib&#47;resin&#47;models&#47;device.coffee)
(lib&#47;resin&#47;models&#47;environment-variables.coffee)
</small>
</li>
<li>
@ -347,11 +355,11 @@
</small>
</li>
<li>
<a href='file/lib/resin/models/environment-variables.coffee.html#remove-' target='main' title='remove'>
<a href='file/lib/resin/models/device.coffee.html#remove-' target='main' title='remove'>
~remove
</a>
<small>
(lib&#47;resin&#47;models&#47;environment-variables.coffee)
(lib&#47;resin&#47;models&#47;device.coffee)
</small>
</li>
<li>

View File

@ -1,5 +1,6 @@
_ = require('lodash')
mkdirp = require('mkdirp')
fsUtils = require('./fs-utils/fs-utils')
errors = require('../errors/errors')
# @nodoc
prefix = null
@ -26,8 +27,8 @@ exports.get = ->
# throw error if error?
#
exports.set = (newPrefix, callback) ->
if not fsUtils.isValidPath(newPrefix)
return callback?(new Error('Invalid path'))
if not _.isString(newPrefix)
return callback?(new errors.InvalidPath(newPrefix))
mkdirp newPrefix, (error) ->
return callback?(error) if error?

View File

@ -1,7 +1,8 @@
_ = require('lodash')
fs = require('fs')
path = require('path')
rimraf = require('rimraf')
fsUtils = require('./fs-utils/fs-utils')
errors = require('../errors/errors')
exports.prefix = require('./data-prefix')
# TODO: codo doesn't recognises functions in this file
@ -16,13 +17,11 @@ haltIfNoPrefix = (callback) ->
# @nodoc
constructPath = (key) ->
if not _.isString(key)
throw new errors.InvalidKey()
prefix = exports.prefix.get()
result = path.join(prefix, key)
if not fsUtils.isValidPath(result)
throw new Error('Invalid path')
return result
return path.join(prefix, key)
# Get data by key
#
@ -142,5 +141,9 @@ exports.has = haltIfNoPrefix (key, callback) ->
# throw error if error?
#
exports.remove = haltIfNoPrefix (key, callback) ->
keyPath = constructPath(key)
try
keyPath = constructPath(key)
catch error
return callback(error)
rimraf(keyPath, callback)

View File

@ -239,3 +239,8 @@ describe 'Data:', ->
], (error) ->
expect(error).to.not.exist
done()
it 'should return an error if key is invalid', (done) ->
data.remove [ 1, 2, 3 ], (error) ->
expect(error).to.be.an.instanceof(Error)
done()

View File

@ -1,17 +0,0 @@
_ = require('lodash')
# Check if valid path
#
# @private
#
# @param {String} path path
# @return {Boolean} is valid path
#
# @todo There should be more complex checks here
#
# @example Is valid path?
# console.log isValidPath('/Users/me') # True
# console.log isValidPath([ 1, 2, 3 ]) # False
#
exports.isValidPath = (p) ->
return _.isString(p)

View File

@ -1,47 +0,0 @@
expect = require('chai').expect
mock = require('../../../../tests/utils/mock')
fsUtils = require('./fs-utils')
settings = require('../../settings')
data = require('../../data/data')
describe 'FsUtils:', ->
describe '#isValidPath()', ->
it 'should return false for invalid paths', ->
for invalidPath in [
{ hello: 'world' }
1234
[ 1, 2, 3 ]
undefined
null
]
expect(fsUtils.isValidPath(invalidPath)).to.be.false
it 'should return true for valid paths', ->
for validPath in [
settings.get('dataPrefix')
'/Users/johndoe'
'../parent'
'./file/../file2'
]
expect(fsUtils.isValidPath(validPath)).to.be.true
describe '#isDirectory()', ->
FILESYSTEM =
text:
name: '/tmp/text'
contents: 'Hello World'
directory:
name: '/tmp/directory'
contents: {}
beforeEach (done) ->
mock.fs.init(FILESYSTEM)
data.prefix.set(settings.get('dataPrefix'), done)
afterEach ->
mock.fs.restore()

View File

@ -48,6 +48,36 @@ exports.InvalidCredentials = class InvalidCredentials extends TypedError
# Error code
code: 1
exports.InvalidKey = class InvalidKey extends TypedError
# Construct an Invalid Key error
#
# @example Invalid key error
# throw new resin.errors.InvalidKey()
# Error: Invalid key
#
constructor: ->
@message = 'Invalid key'
# Error code
code: 1
exports.InvalidPath = class InvalidPath extends TypedError
# Construct an Invalid Path error
#
# @param {String} path the name of the invalid path
#
# @example Invalid path error
# throw new resin.errors.InvalidPath('/tmp')
# Error: Invalid path: /tmp
#
constructor: (path) ->
@message = "Invalid path: #{path}"
# Error code
code: 1
exports.NotAny = class NotAny extends TypedError
# Construct an Not Any error