filegator icon indicating copy to clipboard operation
filegator copied to clipboard

[Feature Request] Unzip and overwrite existing files

Open adriancs2 opened this issue 2 years ago • 4 comments

A zip file is uploaded, and then an unzip is performed. Files extracted/unzip and new files created as follow (for example):

aaa.txt bbb.txt

when the zip file is extracted/unzip for 2nd time, the file list become as follow:

aaa.txt
aaa (1).txt  <-- unwanted duplicated
bbb.txt
bbb (1).txt  <-- unwanted duplicated

when the zip file is extracted/unzip for 3rd time, the file list become as follow:

aaa.txt
aaa (1).txt  <-- unwanted duplicated
aaa (2).txt  <-- unwanted duplicated
bbb.txt
bbb (1).txt  <-- unwanted duplicated
bbb (2).txt  <-- unwanted duplicated

Currently, to avoid duplicate files created, I need to first delete the existing files before unzip.

The problem is I want to update specific files (a lot), but not all files. I have to manually pick the specific files and delete them before unzip. This is highly inconvenient.

I also tried another attempt. which is by creating 2nd folder, unzip the content in 2nd folder, then copy all files from 2nd folder to the target folder, same thing happens. It won't overwrite the files, in stead, it creates duplicates files.

What configurations should be made in order to perform:

  1. unzip and overwrite
  2. copy and overwrite

I have tried to read through the documentations at: https://docs.filegator.io/index.html There is no info related to overwriting files mentioned in documentation.

If I search throught the configuation file --> configuration.php The most relevant that I can find is

overwrite_on_upload' => false,

Can you provide more insights of how to configure this?

  1. unzip and overwrite
  2. copy and overwrite

or if this feature is not implemented yet, I would like to request new feature for this, therefore in the configuration file, new options are available, for example:

<?php

return [
    'public_path' => APP_PUBLIC_PATH,
    'public_dir' => APP_PUBLIC_DIR,
    'overwrite_on_upload' => true,
    'overwrite_on_unzip' => true,    //  <-- new option
    'overwrite_on_copy' => true,     //  <-- new option
    'overwrite_on_move' => true,     //  <-- new option
    ...

adriancs2 avatar Mar 21 '23 23:03 adriancs2

I'm able to do a quick and simple fix for this. Here is what I've done.

Edit the file:

/backend/Services/Storage/Filesystem.php

Edit the following functions:

public function copyFile(string $source, string $destination)
{
    $source = $this->applyPathPrefix($source);
    $destination = $this->joinPaths($this->applyPathPrefix($destination), $this->getBaseName($source));

    while ($this->storage->has($destination)) {
    
        // disable this line
        //$destination = $this->upcountName($destination);
        
        // delete the file
        $this->storage->delete($destination);
    }

    return $this->storage->copy($source, $destination);
}

public function move(string $from, string $to): bool
{
    $from = $this->applyPathPrefix($from);
    $to = $this->applyPathPrefix($to);

    while ($this->storage->has($to)) {
        
        // disable this line
        //$to = $this->upcountName($to);
        
        // delete the file
        $this->storage->delete($to);
    }

    return $this->storage->rename($from, $to);
}

public function store(string $path, string $name, $resource, bool $overwrite = false): bool
{
    $destination = $this->joinPaths($this->applyPathPrefix($path), $name);

    while ($this->storage->has($destination)) {
        
        // delete the file
        $this->storage->delete($destination);
        
        // ignore/skip the rest
        //if ($overwrite) {
        //    $this->storage->delete($destination);
        //} else {
        //    $destination = $this->upcountName($destination);
        //}
    }

    return $this->storage->putStream($destination, $resource);
}

adriancs2 avatar Mar 21 '23 23:03 adriancs2

Hi,

This seems like a valid feature request. I will look into it when I grab some time.

alcalbg avatar Mar 22 '23 07:03 alcalbg

Another possible solution is by providing additional buttons at the front end user interface.

For upload, there will have 2 buttons

  • button 1: upload and creates duplicates if filename existed
  • button 2: upload and overwrite existing files

For unzip,

  • button 1: unzip and creates duplicates if filename exists
  • button 2: unzip and overwrite existing files

For copy or move

  • button 1: copy/move, creates duplicates if filename exists
  • button 2: copy/move, overwrite existing files

with this solution, this will eleminate the need to configure the settings file.

both options "create duplicates" and "overwrite" are available in user interface, user can easily freely to choose whether to create duplicates or overwrite based on his/her unique situation in real use.

adriancs2 avatar Mar 28 '23 02:03 adriancs2

For me it's completely different. oO I have version 7.9.3 and when I unzip a zip file it simply doesn't overwrite existing files. It doesn't create additional files either.

So in your example above I'm stuck with the original aaa and bbb files. No duplicates are created. Basically it skips existing files. Unfortunately it doesn't give any error message, either.

The buttons would be VERY NICE.

Digioso avatar Nov 26 '23 20:11 Digioso