Skip to content

Commit

Permalink
fs, feat: support fs.watchFile/fs.unwatchFile.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardo2016 committed Jul 6, 2020
1 parent 65d94ef commit 03bb2e0
Show file tree
Hide file tree
Showing 14 changed files with 1,418 additions and 269 deletions.
10 changes: 5 additions & 5 deletions .travis/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ set -ev
if [[ $TRAVIS_OS_NAME == 'linux' ]]; then
if [[ $TARGET_ARCH == "amd64" ]]; then
# Test on ubuntu:18.04
DIR=`pwd`;sudo docker run -it -v ${DIR}:/home/ci ubuntu:18.04 /bin/sh -c "cd /home/ci; ./bin/Linux_amd64_release/fibjs test/main.js"
DIR=`pwd`;sudo docker run -it --env CI=$CI -v ${DIR}:/home/ci ubuntu:18.04 /bin/sh -c "cd /home/ci; ./bin/Linux_amd64_release/fibjs test/main.js"

# Test on ubuntu:16.04
DIR=`pwd`;sudo docker run -it -v ${DIR}:/home/ci ubuntu:16.04 /bin/sh -c "cd /home/ci; ./bin/Linux_amd64_release/fibjs test/main.js"
DIR=`pwd`;sudo docker run -it --env CI=$CI -v ${DIR}:/home/ci ubuntu:16.04 /bin/sh -c "cd /home/ci; ./bin/Linux_amd64_release/fibjs test/main.js"

# Test on ubuntu:14.04
DIR=`pwd`;sudo docker run -it -v ${DIR}:/home/ci ubuntu:14.04 /bin/sh -c "cd /home/ci; ./bin/Linux_amd64_release/fibjs test/main.js"
DIR=`pwd`;sudo docker run -it --env CI=$CI -v ${DIR}:/home/ci ubuntu:14.04 /bin/sh -c "cd /home/ci; ./bin/Linux_amd64_release/fibjs test/main.js"
fi

if [[ $TARGET_ARCH == "arm" ]]; then
# Test on arm using qemu
sudo docker run --rm --privileged multiarch/qemu-user-static:register
DIR=`pwd`;sudo docker run --privileged=true -it -v ${DIR}:/home/ci fibjs/build-env:clang /bin/sh -c "
DIR=`pwd`;sudo docker run --privileged=true -it --env CI=$CI -v ${DIR}:/home/ci fibjs/build-env:clang /bin/sh -c "
cd /home;
sh init_armhf.sh;
cp -f ./ci/bin/Linux_arm_release/fibjs ./arm_root_fs/bin/fibjs;
Expand All @@ -28,7 +28,7 @@ if [[ $TRAVIS_OS_NAME == 'linux' ]]; then
if [[ $TARGET_ARCH == "arm64" ]]; then
# Test on arm64 using qemu
sudo docker run --rm --privileged multiarch/qemu-user-static:register
DIR=`pwd`;sudo docker run --privileged=true -it -v ${DIR}:/home/ci fibjs/build-env:clang /bin/sh -c "
DIR=`pwd`;sudo docker run --privileged=true -it --env CI=$CI -v ${DIR}:/home/ci fibjs/build-env:clang /bin/sh -c "
cd /home;
sh init_arm64.sh;
cp -f ./ci/bin/Linux_arm64_release/fibjs ./arm64_root_fs/bin/fibjs;
Expand Down
28 changes: 28 additions & 0 deletions fibjs/include/AsyncUV.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @author Richard
* @email ricahrdo2016@mail.com
* @create date 2020-06-26 19:00:27
* @modify date 2020-06-26 19:00:27
* @desc general AsyncUV Item Runnin in AsyncUVLoopThread
*/

#ifndef ASYNCUV_H_
#define ASYNCUV_H_

#include "AsyncCall.h"

namespace fibjs {
class AsyncUVTask: public AsyncEvent
{
public:
AsyncUVTask(): AsyncEvent(NULL)
{
};
~AsyncUVTask()
{
};
};

}

#endif // ASYNCUV_H_
15 changes: 10 additions & 5 deletions fibjs/include/FSWatcher.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
* @author Richard
* @email ricahrdo2016@mail.com
* @create date 2020-06-28 16:15:41
* @modify date 2020-06-28 16:15:41
* @desc
*/

#include "ifs/FSWatcher.h"
#include "ifs/fs.h"
#include "EventEmitter.h"
Expand All @@ -6,6 +14,7 @@
#include "Timer.h"
#include "utf8.h"
#include "Stat.h"
#include "AsyncUV.h"

#ifndef _fj_FSWATCHER_H
#define _fj_FSWATCHER_H
Expand Down Expand Up @@ -45,7 +54,7 @@ class FSWatcher : public FSWatcher_base {
EVENT_FUNC(error);

public:
class AsyncWatchFSProc : public AsyncEvent {
class AsyncWatchFSProc : public AsyncUVTask {
public:
AsyncWatchFSProc(FSWatcher* watcher)
: m_watcher(watcher)
Expand Down Expand Up @@ -99,7 +108,6 @@ class FSWatcher : public FSWatcher_base {
public:
FSWatcher* m_watcher;
uv_fs_event_t m_fs_handle;
exlib::Locker m_locker;

private:
static void fs_event_cb(uv_fs_event_t* fs_event, const char* filename, int events, int status)
Expand All @@ -112,8 +120,6 @@ class FSWatcher : public FSWatcher_base {
if (!p)
return;

p->m_locker.lock(p);

uv_handle_t* handle = (uv_handle_t*)fs_event;
if (p->m_watcher->m_closed) {
handle->data = (void*)p;
Expand All @@ -127,7 +133,6 @@ class FSWatcher : public FSWatcher_base {

p->on_watched(fullname, events, status);
}
p->m_locker.unlock(p);
}
};

Expand Down
Loading

0 comments on commit 03bb2e0

Please sign in to comment.