Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"main": "./lib/main.js",
"name": "pathwatcher",
"description": "Watch files and directories for changes",
"version": "4.4.4",
"version": "4.4.5-0",
"licenses": [
{
"type": "MIT",
Expand Down
21 changes: 21 additions & 0 deletions spec/file-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ fs = require 'fs-plus'
temp = require 'temp'
File = require '../lib/file'
PathWatcher = require '../lib/main'
Q = require 'q'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't Atom transitioning to native promises now? Or is that just for Atom packages and not Node ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's node modules too; in fact, on the master branch of this repo (and for versions >= 5), we're no longer using Q. Once we upgrade electron, we will be able to stop using Q in Atom, and upgrade it to use a newer pathwatcher version. This PR is against an older version though, in which we haven't yet removed Q.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, gotcha. Didn't realize this was on an old version of pathwatcher.


describe 'File', ->
[filePath, file] = []
Expand Down Expand Up @@ -49,6 +50,26 @@ describe 'File', ->
expect(file.getDigestSync()).toBe 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
expect(file.readSync.callCount).toBe 1

file.writeSync('x')

expect(file.getDigestSync()).toBe '11f6ad8ec52a2984abaafd7c3b516503785c2072'
expect(file.readSync.callCount).toBe 1
expect(file.getDigestSync()).toBe '11f6ad8ec52a2984abaafd7c3b516503785c2072'
expect(file.readSync.callCount).toBe 1

readDeferred = Q.defer()
spyOn(file, 'read').andReturn(readDeferred.promise)

changed = false
file.onDidChange -> changed = true
fs.writeFileSync(filePath, 'y')

waitsFor -> file.getDigestSync() is '95cb0bfd2977c761298d9624e4b4d4c72a39974a'

runs ->
readDeferred.resolve("y")
expect(file.getDigestSync()).toBe '95cb0bfd2977c761298d9624e4b4d4c72a39974a'

describe '::create()', ->
[callback, nonExistentFile, tempDir] = []

Expand Down
4 changes: 4 additions & 0 deletions src/file.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class File
@exists().then (previouslyExisted) =>
@writeFile(@getPath(), text).then =>
@cachedContents = text
@setDigest(text)
@subscribeToNativeChangeEvents() if not previouslyExisted and @hasSubscriptions()
undefined

Expand All @@ -303,6 +304,7 @@ class File
previouslyExisted = @existsSync()
@writeFileWithPrivilegeEscalationSync(@getPath(), text)
@cachedContents = text
@setDigest(text)
@subscribeToNativeChangeEvents() if not previouslyExisted and @hasSubscriptions()
undefined

Expand Down Expand Up @@ -346,6 +348,8 @@ class File
@emitter.emit 'did-rename'
when 'change', 'resurrect'
oldContents = @cachedContents
@cachedContents = null
@digest = null
handleReadError = (error) =>
# We cant read the file, so we GTFO on the watch
@unsubscribeFromNativeChangeEvents()
Expand Down