Skip to content

Commit

Permalink
Add a command to list files (synchronized or ignored)
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Mar 18, 2016
1 parent 4cc7ed5 commit 52811e3
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
16 changes: 16 additions & 0 deletions doc/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,19 @@ You can launch cozy-desktop directly in coffee:
```bash
DEBUG=true node_modules/.bin/coffee src/bin/cli.coffee sync
```


Debug ignored files
-------------------

You can list the files and folder that are synchronized with:

```bash
cozy-desktop ls
```

And those which are ignored:

```bash
cozy-desktop ls --ignored
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"printit": "0.1.18",
"progress": "1.1.8",
"read": "1.0.7",
"readdirp": "2.0.0",
"request-json-light": "0.5.22"
},
"devDependencies": {
Expand Down
40 changes: 32 additions & 8 deletions src/app.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
async = require 'async'
fs = require 'fs'
path = require 'path-extra'
os = require 'os'
url = require 'url'
log = require('printit')
async = require 'async'
fs = require 'fs'
os = require 'os'
path = require 'path-extra'
readdirp = require 'readdirp'
url = require 'url'
log = require('printit')
prefix: 'Cozy Desktop '
date: true

Expand Down Expand Up @@ -109,14 +110,19 @@ class App
callback? err


# Instanciate some objects before sync
instanciate: ->
# Load ignore rules
loadIgnore: ->
try
ignored = fs.readFileSync(path.join @basePath, '.cozyignore')
ignored = ignored.toString().split('\n')
catch error
ignored = []
@ignore = new Ignore(ignored).addDefaultRules()


# Instanciate some objects before sync
instanciate: ->
@loadIgnore()
@merge = new Merge @pouch
@prep = new Prep @merge, @ignore
@local = @merge.local = new Local @config, @prep, @pouch
Expand Down Expand Up @@ -157,6 +163,24 @@ class App
@local?.watcher.debug()


# Call the callback for each file
walkFiles: (args, callback) ->
@loadIgnore()
options =
root: @basePath
directoryFilter: '!.cozy-desktop'
entryType: 'both'
readdirp options
.on 'warn', (err) -> log.warn err
.on 'error', (err) -> log.error err
.on 'data', (data) =>
doc =
_id: data.path
docType: if data.stat.isFile() then 'file' else 'folder'
if @ignore.isIgnored(doc) is args.ignored?
callback data.path


# Recreate the local pouch database
resetDatabase: (callback) =>
@askConfirmation (err, ok) =>
Expand Down
8 changes: 8 additions & 0 deletions src/bin/cli.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ program
The README has more instructions about that.
"""

program
.command 'ls'
.description 'List local files that are synchronized with the remote cozy'
.option('-i, --ignored', 'List ignored files')
.action (args) ->
app.walkFiles args, (file) ->
console.log file

program
.command 'reset-database'
.description 'Recreates the local database'
Expand Down

0 comments on commit 52811e3

Please sign in to comment.