1 | 'use strict';
|
2 |
|
3 | const fs = require('fs');
|
4 | const mkdirpsync = require('./mkdirpSync');
|
5 | const path = require('path');
|
6 |
|
7 | var writeLazySafeSync = (file_path, body) => {
|
8 | try {
|
9 | var data = fs.readFileSync(file_path, 'utf-8');
|
10 | if(data == body)
|
11 | return false;
|
12 | } catch(err) { }
|
13 |
|
14 | mkdirpsync(path.dirname(file_path));
|
15 | var tmp_path = file_path + '.tmp';
|
16 | fs.writeFileSync(tmp_path, body);
|
17 | fs.renameSync(tmp_path, file_path);
|
18 | return true;
|
19 | };
|
20 |
|
21 | module.exports = writeLazySafeSync;
|