Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After download file is complete the file is "LOCKED" #17

Open
pantchox opened this issue Mar 26, 2017 · 3 comments
Open

After download file is complete the file is "LOCKED" #17

pantchox opened this issue Mar 26, 2017 · 3 comments

Comments

@pantchox
Copy link

When the download finishes i am unable to do files action such as move/del the downloaded file(s).
I assume somewhere when the download is finished the file handler is not released. only if i close the program that runs the downloader then i can do the specified actions.

please elaborate.

P.S thanks for this great lib!

@pantchox
Copy link
Author

Another issue i have noticed.
I am using my client to sync files from server, as i download the file which is a zip archive i run a zip test and md5 check (upon server notifying the md5) and if it does not match it is a failure and the file need to be DELETED and redownloaded.
the DELETE command is failing upon reason from my first comment, there for when it finish the redownload it can not rename it to the original filename because the file that failed which has the same name could not be deleted which makes the events hang and get stack.

this is a real issue i will need to investigate this repo source and mt-downloader spec to see this repo complies with the events of releasing the file handler.

@pantchox
Copy link
Author

pantchox commented Mar 31, 2017

Hi,
I think the issue is happening only on windows and in a very WEIRD way.

var fs = require('fs');
var os   = require('os');
var path = require('path');
var Downloader = require('../lib/Downloader');

// Create new downloader
var downloader = new Downloader();
var fileUrl = 'http://vhost2.hansenet.de/10_mb_file.bin';
var fileSavePath = path.join(__dirname, 'mtFileDlTest1.zip');
console.log('File will be downloaded from '+ fileUrl +' to '+ fileSavePath);

// Start download
var dl = downloader.download(fileUrl, fileSavePath)
		  .start();

dl.on('end', function() {
		fs.unlink(fileSavePath, function(err) {
    	if ( err ) {
			console.log('ERROR: ' + err);
		} else {
			console.log('starting a new download on same name!');
			var downloader2 = new Downloader();
			var fileUrl2 = 'http://vhost2.hansenet.de/10_mb_file.bin';
			var fileSavePath2 = path.join(__dirname, 'mtFileDlTest1.zip');
			console.log('File will be downloaded from '+ fileUrl2 +' to '+ fileSavePath2);
			// Start download
			var dl2 = downloader2.download(fileUrl2, fileSavePath2)
			.start();
				require('./_handleEvents')(dl2);
				require('./_printStats')(dl2);


			}});

	});
// Import generic examples for handling events and printing stats
require('./_handleEvents')(dl);
require('./_printStats')(dl);

here i pasted a modified code from the example folder, it downloads a file then when it is finished it will delete it - if you follow my comments i was having issue to delete it after download assuming the file handler is still on and locking the file.

In the fs.unlink() command after i run it if there is an error it will show the error and exit, if not it will continue to redownload the file again.
On linux everything works fine it deletes the file no error and redownload again,
However in windows it also works fine, the unlink does not return any error but while it is downloading the second time i can still see the first downloaded file present, then when the 2nd file is finished downloading it can not change the MTD file name to original file name because the file STILL exists and prob' locked, after the program finishes (with loads of retrys) only then the file is deleted.

I don't know if this is an issue of mtd-files-downloader or mt-downloader or windows just sucks.

I have windows 7 64bit and node v6.60

So i assume this is a windows issue, which is the machine i do my development but thankfully it will run on linux.

@hgouveia
Copy link

I'm having same issue, after download or stop , the file remains locked and i can't find any way to unlock the file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants