Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
14be1e66
Commit
14be1e66
authored
13 years ago
by
mcmlxxix
Browse files
Options
Downloads
Patches
Plain Diff
add modopts.js support
some minor updates
parent
3a85f064
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
exec/load/json-db.js
+11
-7
11 additions, 7 deletions
exec/load/json-db.js
with
11 additions
and
7 deletions
exec/load/json-db.js
+
11
−
7
View file @
14be1e66
...
@@ -42,6 +42,9 @@ function JSONdb (fileName) {
...
@@ -42,6 +42,9 @@ function JSONdb (fileName) {
else
else
this
.
file
=
undefined
;
this
.
file
=
undefined
;
/* load modopts */
this
.
options
=
load
(
"
modopts.js
"
,
"
jsondb
"
);
/* master database object */
/* master database object */
this
.
data
=
{};
this
.
data
=
{};
...
@@ -63,8 +66,6 @@ function JSONdb (fileName) {
...
@@ -63,8 +66,6 @@ function JSONdb (fileName) {
/* file read buffer */
/* file read buffer */
FILE_BUFFER
:
65535
,
FILE_BUFFER
:
65535
,
/* autosave interval */
AUTO_SAVE
:
300
/*seconds*/
*
1000
,
LAST_SAVE
:
-
1
,
LAST_SAVE
:
-
1
,
UPDATES
:
false
,
UPDATES
:
false
,
...
@@ -411,13 +412,16 @@ function JSONdb (fileName) {
...
@@ -411,13 +412,16 @@ function JSONdb (fileName) {
if
(
!
timestamp
)
if
(
!
timestamp
)
timestamp
=
Date
.
now
();
timestamp
=
Date
.
now
();
/* if we are due for a data update, save everything to file */
/* if we are due for a data update, save everything to file */
if
(
timestamp
-
this
.
settings
.
LAST_SAVE
>=
this
.
settings
.
AUTO_SAVE
)
{
if
(
timestamp
-
this
.
settings
.
LAST_SAVE
>=
(
this
.
options
.
save_interval
*
1000
)
)
{
//TODO: create n backups before overwriting data file
//TODO: create n backups before overwriting data file
this
.
file
.
open
(
"
w
"
);
this
.
file
.
open
(
"
w
"
);
// This function gets called every 30 seconds or so
// This function gets called every 30 seconds or so
// And flushes all objects to disk in case of crash
// And flushes all objects to disk in case of crash
// Also, this is called on clean exit.
// Also, this is called on clean exit.
this
.
file
.
write
(
JSON
.
stringify
(
this
.
data
,
undefined
,
4
));
if
(
this
.
options
.
readable
)
this
.
file
.
write
(
JSON
.
stringify
(
this
.
data
,
undefined
,
'
\t
'
));
else
this
.
file
.
write
(
JSON
.
stringify
(
this
.
data
));
this
.
file
.
close
();
this
.
file
.
close
();
this
.
settings
.
LAST_SAVE
=
timestamp
;
this
.
settings
.
LAST_SAVE
=
timestamp
;
this
.
settings
.
UPDATES
=
false
;
this
.
settings
.
UPDATES
=
false
;
...
@@ -445,7 +449,7 @@ function JSONdb (fileName) {
...
@@ -445,7 +449,7 @@ function JSONdb (fileName) {
/* initialize autosave timer */
/* initialize autosave timer */
this
.
settings
.
LAST_SAVE
=
Date
.
now
();
this
.
settings
.
LAST_SAVE
=
Date
.
now
();
log
(
LOG_INFO
,
"
JSON
database initialized (v
"
+
this
.
VERSION
+
"
)
"
);
log
(
LOG_INFO
,
"
database initialized (v
"
+
this
.
VERSION
+
"
)
"
);
}
}
/* release any locks or subscriptions held by a disconnected client */
/* release any locks or subscriptions held by a disconnected client */
...
@@ -642,11 +646,11 @@ function JSONdb (fileName) {
...
@@ -642,11 +646,11 @@ function JSONdb (fileName) {
/* if the requested child object does not exist, create it */
/* if the requested child object does not exist, create it */
function
verify
(
data
,
shadow
,
child_name
)
{
function
verify
(
data
,
shadow
,
child_name
)
{
if
(
!
data
[
child_name
])
{
if
(
data
[
child_name
]
===
undefined
)
{
log
(
LOG_DEBUG
,
"
creating new data:
"
+
child_name
);
log
(
LOG_DEBUG
,
"
creating new data:
"
+
child_name
);
data
[
child_name
]
=
{};
data
[
child_name
]
=
{};
}
}
if
(
!
shadow
[
child_name
])
{
if
(
shadow
[
child_name
]
===
undefined
)
{
log
(
LOG_DEBUG
,
"
creating new shadow:
"
+
child_name
);
log
(
LOG_DEBUG
,
"
creating new shadow:
"
+
child_name
);
shadow
[
child_name
]
=
new
Shadow
();
shadow
[
child_name
]
=
new
Shadow
();
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment