#21 fs.rename fails on cross device.

Closed
n2omatt wants to merge 45 commits from n2omatt/CrossDevice_Rename_Issues into libreflix/master
n2omatt commented 6 years ago

Well, I'm working on the crop image feature - issue #19 and for that I need (obviously) upload some images. But on my current GNU/Linux setup I'm using a separated disk for /home (where the project resides buried into a deep path) and another disk for / (/usr, /tmp, etc...).

Actually, this is quite common setup (or a variation of..) for unix-like, so I'm not a snowflake here ;D - But I ran into some problem with the ./controlers/upload.js uploadImage function.

The main reason is that we were using fs.rename, and this can go wrong if (as in my case) the tmpfs is mounted on another device.

To fix this is quite easy, just copy and remove the old file (not need actually but good to maintain the storage quite clean), unfortunately, I found that the default fs module has any of those functions.

The solution is use another (seems like a drop in replacement) package that provides the functionality that we want to! fs-extra provides exactly what is need. They're MIT licensed so we think that we're ok!

Here a snippet of the error:

(node:7873) [DEP0013] DeprecationWarning: Calling an asynchronous function without callback is deprecated.
POST /upload 200 5.762 ms - -
fs.js:113
      throw err;  // Forgot a callback but don't know where? Use NODE_DEBUG=fs
      ^
Error: EXDEV: cross-device link not permitted, rename '/tmp/upload_5e910a6fb6c0a8753ba68a309b667f0b' -> '/home/n2omatt/Documents/Projects/N2OMatt/libreflix/public/media/dee15230-f191-11e7-9fbb-d34481d90ab8logo.jpg'

Related stuff:

https://stackoverflow.com/questions/12196163/node-js-fs-rename-doesnt-work
https://github.com/nodejs/node-v0.x-archive/issues/5287
https://github.com/nodejs/node-v0.x-archive/issues/685
https://wiki.archlinux.org/index.php/tmpfs
Well, I'm working on the [crop image feature - issue #19](https://notabug.org/libreflix/libreflix/issues/19) and for that I need (obviously) upload some images. But on my current GNU/Linux setup I'm using a separated disk for /home (where the project resides buried into a deep path) and another disk for / (/usr, /tmp, etc...). Actually, this is quite common setup (or a variation of..) for unix-like, so I'm not a snowflake here ;D - But I ran into some problem with the ./controlers/upload.js uploadImage function. The main reason is that we were using fs.rename, and this can go wrong if (as in my case) the tmpfs is mounted on another device. To fix this is quite easy, just copy and remove the old file (not need actually but good to maintain the storage quite clean), unfortunately, I found that the default fs module has any of those functions. The solution is use another (seems like a drop in replacement) package that provides the functionality that we want to! [fs-extra](https://github.com/jprichardson/node-fs-extra) provides exactly what is need. They're MIT licensed so we think that we're ok! Here a snippet of the error: ``` (node:7873) [DEP0013] DeprecationWarning: Calling an asynchronous function without callback is deprecated. POST /upload 200 5.762 ms - - fs.js:113 throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs ^ Error: EXDEV: cross-device link not permitted, rename '/tmp/upload_5e910a6fb6c0a8753ba68a309b667f0b' -> '/home/n2omatt/Documents/Projects/N2OMatt/libreflix/public/media/dee15230-f191-11e7-9fbb-d34481d90ab8logo.jpg' ``` Related stuff: https://stackoverflow.com/questions/12196163/node-js-fs-rename-doesnt-work https://github.com/nodejs/node-v0.x-archive/issues/5287 https://github.com/nodejs/node-v0.x-archive/issues/685 https://wiki.archlinux.org/index.php/tmpfs
guilmour commented 6 years ago
Owner

Hey, buddy. Sorry for the slow reply.

I'll check it and test it this weekend. My computer's GPU just died and there is no video output in the motherboard. I use to bake the video card, but it seems no to be working anymore. :(

Thank you for the hard work.

<3

Hey, buddy. Sorry for the slow reply. I'll check it and test it this weekend. My computer's GPU just died and there is no video output in the motherboard. I use to [bake the video card](https://lifehacker.com/5823227/save-dying-video-cards-with-a-quick-bake-in-the-oven), but it seems no to be working anymore. :( Thank you for the hard work. <3
n2omatt commented 6 years ago
Poster

Oh... that's sad (for your video card) ;D But there's no problem at all! I meanwhile I'm working on the crop feature ;D

Oh... that's sad (for your video card) ;D But there's no problem at all! I meanwhile I'm working on the crop feature ;D
jotarios commented 6 years ago

Hi there! I have some doubts: Why are you changing Libreflix for acredito.me? in controllers/contact.js and controllers/user.js.

Then, why did you deleted: controllers/watch.js?

Thank you, happy coding!

Hi there! I have some doubts: Why are you changing Libreflix for acredito.me? in **controllers/contact.js** and **controllers/user.js**. Then, why did you deleted: **controllers/watch.js**? Thank you, happy coding!
guilmour commented 6 years ago
Owner

Oh, It was because I reuse some code to Libreflix from this another project that I was working called Acredito.me. And Matt was some commits behind when I updated this.

But no problem at all, because I will test the PR and so I will merge only the two last commits, and not the entire commits.

Thank you, @jotarios for reviewing it.

Oh, It was because I reuse some code to Libreflix from this another project that I was working called Acredito.me. And Matt was some commits behind when I updated this. But no problem at all, because I will test the PR and so I will merge only the two last commits, and not the entire commits. Thank you, @jotarios for reviewing it.
jotarios commented 6 years ago

Thank you, @guilmour!

It's clear now!

Thank you, @guilmour! It's clear now!
guilmour commented 6 years ago
Owner

Just merged the last two commits. Thank you, Matt! <3

Just merged the last two commits. Thank you, Matt! <3
Please reopen this pull request to perform merge operation.
Sign in to join this conversation.
Loading...
Cancel
Save
There is no content yet.