New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

directory-sync

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

directory-sync - npm Package Compare versions

Comparing version 2.0.10 to 2.0.11

3

package.json
{
"name": "directory-sync",
"version": "2.0.10",
"version": "2.0.11",
"description": "Easily synchronize directories between two machines over the internet.",

@@ -33,4 +33,5 @@ "main": "index.js",

"node-fetch": "^3.2.0",
"temp-dir": "^2.0.0",
"ws": "^8.5.0"
}
}

@@ -0,1 +1,2 @@

import tempDirectoryRaw from 'temp-dir';
import Stream from 'stream';

@@ -6,3 +7,6 @@ import FileSystemSync from 'fs';

import { randomUUID } from 'crypto';
import { to_forward_slashes, generate_md5_hash } from '../../utils/operators.js';
const SYSTEM_TEMPORARY_PATH = to_forward_slashes(tempDirectoryRaw);
export default class DirectoryManager {

@@ -23,3 +27,8 @@ #map;

_absolute_path(uri) {
return `${this.#map.path}${uri}`;
// Return the temporary directory system path if the uri is a temporary uri
if (uri.startsWith('temporary://')) {
return `${SYSTEM_TEMPORARY_PATH}${uri.replace('temporary://', '/')}`;
} else {
return `${this.#map.path}${uri}`;
}
}

@@ -67,3 +76,3 @@

* @param {String|Buffer|Stream.Readable} data
* @param {String=} md5
* @param {String} md5
* @param {Boolean=} supress

@@ -74,2 +83,7 @@ */

// Ensure this write operation has an accompanying md5 hash
const has_length = data instanceof Stream.Readable || data.length > 0;
if (typeof md5 !== 'string' || (has_length && md5.length == 0))
throw new Error('MD5 Hash Is Required For Checksum Validation When Writing Content');
// Suppress the file_change event if file already exists locally

@@ -98,6 +112,9 @@ if (this.#map.get(uri)) {

// Wait for the md5 of this file to update
const written_md5 = await new Promise((resolve) =>
this.#map.once(`md5_change:${uri}`, ({ stats }) => resolve(stats.md5))
);
// If this is temporary file, generate the md5 hash from the file path
// else wait for the Directory Map to load the new md5 hash
const written_md5 = uri.startsWith('temporary://')
? await generate_md5_hash(path)
: await new Promise((resolve) =>
this.#map.once(`md5_change:${uri}`, ({ stats }) => resolve(stats.md5))
);

@@ -125,3 +142,3 @@ // Throw an error if the md5's do not match

// Attempt to write the file safely to a temporary file
const temp_uri = `/temp-${randomUUID()}`;
const temp_uri = `temporary://temp-${randomUUID()}`;
try {

@@ -128,0 +145,0 @@ await this.write(temp_uri, data, md5, true);

@@ -187,2 +187,5 @@ import Path from 'path';

supress(uri, event, amount = 1) {
// Ignore temporary uris
if (uri.startsWith('temporary://')) return;
// Initialize the supression key or increment the amount of supressions

@@ -189,0 +192,0 @@ const key = `${event}:${uri}`;

@@ -589,2 +589,3 @@ import fetch from 'node-fetch';

this._log('DOWNLOAD', `${uri} - FILE - FAILED - RETRY - ${cooldown}ms`);
this.emit('error', error);
await async_wait(cooldown);

@@ -634,5 +635,4 @@

if (status !== 200)
// Ensure the response status code is valid
throw new Error(`_upload_file(${uri}) -> HTTP ${status}`);
// Ensure the response status code is valid
if (status !== 200) throw new Error(`_upload_file(${uri}) -> HTTP ${status}`);

@@ -639,0 +639,0 @@ this._log('UPLOAD', `${uri} - FILE - END - ${Date.now() - start_time}ms`);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc