Skip to content

Commit

Permalink
Remove PID.
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonWeber committed Feb 2, 2024
1 parent 935ca14 commit 3f969ef
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 37 deletions.
11 changes: 5 additions & 6 deletions Library/Sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class Sender {
private _fileCleanupTimer: NodeJS.Timer;
private _redirectedHost: string = null;
private _tempDir: string;
private _processId: number = process.pid;
private _requestTimedOut: boolean;
protected _resendInterval: number;
protected _maxBytesOnDisk: number;
Expand Down Expand Up @@ -429,7 +428,7 @@ class Sender {
try {
//create file - file name for now is the timestamp, a better approach would be a UUID but that
//would require an external dependency
var fileName = `${new Date().getTime()}.${this._processId}.ai.json`;
var fileName = `${new Date().getTime()}.ai.json`;
var fileFullPath = path.join(this._tempDir, fileName);

// Mode 600 is w/r for creator and no read access for others (only applies on *nix)
Expand Down Expand Up @@ -466,7 +465,7 @@ class Sender {

//create file - file name for now is the timestamp, a better approach would be a UUID but that
//would require an external dependency
var fileName = `${new Date().getTime()}.${this._processId}.ai.json`;
var fileName = `${new Date().getTime()}.ai.json`;
var fileFullPath = path.join(this._tempDir, fileName);

// Mode 600 is w/r for creator and no access for anyone else (only applies on *nix)
Expand All @@ -486,7 +485,7 @@ class Sender {
private async _sendFirstFileOnDisk(): Promise<void> {
try {
let files = await FileSystemHelper.readdirAsync(this._tempDir);
files = files.filter(f => path.basename(f).indexOf(`${process.pid}.ai.json`) > -1);
files = files.filter(f => path.basename(f).indexOf(".ai.json") > -1);
if (files.length > 0) {
var firstFile = files[0];
var filePath = path.join(this._tempDir, firstFile);
Expand All @@ -511,11 +510,11 @@ class Sender {
private async _fileCleanupTask(): Promise<void> {
try {
let files = await FileSystemHelper.readdirAsync(this._tempDir);
files = files.filter(f => path.basename(f).indexOf(`${this._processId}.ai.json`) > -1);
files = files.filter(f => path.basename(f).indexOf(".ai.json") > -1);
if (files.length > 0) {
for (let i = 0; i < files.length; i++) {
// Check expiration
let fileCreationDate: Date = new Date(parseInt(files[i].split(`${this._processId}.ai.json`)[0]));
let fileCreationDate: Date = new Date(parseInt(files[i].split(".ai.json")[0]));
let expired = new Date(+(new Date()) - Sender.FILE_RETEMPTION_PERIOD) > fileCreationDate;
if (expired) {
var filePath = path.join(this._tempDir, files[i]);
Expand Down
4 changes: 2 additions & 2 deletions Tests/EndToEnd.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ describe("EndToEnd", () => {
writeFile = sandbox.stub(FileSystemHelper, 'writeFileAsync');
writeFileSync = sandbox.stub(fs, 'writeFileSync');
existsSync = sandbox.stub(fs, 'existsSync').returns(true);
readdir = sandbox.stub(FileSystemHelper, 'readdirAsync').returns([`${process.pid}.ai.json`]);
readdirSync = sandbox.stub(fs, 'readdirSync').returns([`${process.pid}.ai.json`]);
readdir = sandbox.stub(FileSystemHelper, 'readdirAsync').returns(['1.ai.json']);
readdirSync = sandbox.stub(fs, 'readdirSync').returns(['.ai.json']);
stat = sandbox.stub(FileSystemHelper, 'statAsync').returns({ isFile: () => true, size: 8000 });
statSync = sandbox.stub(fs, 'statSync').returns({ isFile: () => true, size: 8000 });
lstat = sandbox.stub(FileSystemHelper, 'lstatAsync').returns({ isDirectory: () => true });
Expand Down
80 changes: 51 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3f969ef

Please sign in to comment.