• Post Reply Bookmark Topic Watch Topic
  • New Topic

Renaming file on Linux Server Not Working  RSS feed

 
Mike London
Ranch Hand
Posts: 1505
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have code that works perfectly on the Mac Desktop to rename a file I'm processing. Yet, that same code run against a Linux server doesn't work correctly.

BASIC IDEA:
--------------
I'm using a temp file to process some results.
Then, I delete the original file
Then, I rename the temp file to the original file.

       Files.move(pathCsfTempFile, pathCsfFile, REPLACE_EXISTING);

Then, I close files.
Then, I close the connection.

But, when I run that same code run against the Linux server I get the temp file coming back after I close the connection and the original file being gone.

Stepping through the code looks like everything is OK on the Linux side. That is, until the program is done. Then the renamed file is gone and the temp file reappears.

Clearly missing something ... Baffling.

Suggestions welcome!!

- mike

 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shouldn't you close the file, then move it?

I think that if you still have the file handle open, then move it, closing it could create it again...

it is early, i've not had any coffee, so I could be wrong here.
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred pointed out.

Now that renaming deleting step might not needed.

You are using REPLACE_EXISTING attribute, just create that temp file same name as original, and once you done you move it to the location where actual original is.


Be careful with those original overriding, if it is daily task, back-up at least week's files and only later delete if all went smoothly.
 
Mike London
Ranch Hand
Posts: 1505
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:fred pointed out.

Now that renaming deleting step might not needed.

You are using REPLACE_EXISTING attribute, just create that temp file same name as original, and once you done you move it to the location where actual original is.


Be careful with those original overriding, if it is daily task, back-up at least week's files and only later delete if all went smoothly.


Your suggestion did work.

What was confusing is that on the Mac and Linux I was working in the same directory using files with "temp" and the original file. On the mac it was fine, but on Linux it showed that problem. In any case, your idea of creating the temp file in another directory (in my case local desktop) and then doing the "move" to the Linux server worked perfectly.

Thanks very much!!!

- mike
 
Mike London
Ranch Hand
Posts: 1505
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:shouldn't you close the file, then move it?

I think that if you still have the file handle open, then move it, closing it could create it again...

it is early, i've not had any coffee, so I could be wrong here.


Hey Fred,

Appreciated your idea. I tried that but it didn't resolve the issue.

See the resolution posting below.

Thanks again.

- mike
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!