Changeset 3011


Ignore:
Timestamp:
Dec 8, 2006, 1:04:29 PM (16 years ago)
Author:
Martin Svensson
Message:

Fixes #444 Plugins should check that they are allowed to create/overwrite files

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/plugin/AbstractExporterPlugin.java

    r2981 r3011  
    332332    return value == null ? false : value;
    333333  }
     334 
     335  /**
     336      See if file path already exists and if it's allowed to overwrite it.     
     337      @param strPath The file path to be checked.
     338      @param overwrite TRUE If it is allowed to overwrite the file, FALSE otherwise.
     339      @return FALSE If the file path exists and isn't allowed to be overwritten or TRUE otherwise.
     340  */
     341  protected boolean pathCanBeUsed(String strPath, boolean overwrite)
     342  {   
     343    DbControl dc = sc.newDbControl();
     344    Path path = new Path(strPath, Path.Type.FILE);
     345    File file = File.getByPath(dc, path, true);
     346   
     347    if (!overwrite && file.isInDatabase() && !file.isRemoved())
     348    {
     349      dc.close();
     350      return false;     
     351    }
     352    else
     353    {
     354      dc.close();
     355      return true;
     356    }
     357  }
    334358}
  • trunk/src/plugins/core/net/sf/basedb/plugins/HelpExporter.java

    r2942 r3011  
    202202          response.setError(errors.size() + " invalid parameters were found in the request",errors);
    203203          return;
    204         }
    205 
     204        }       
     205       
    206206        storeValue(job, request, ri.getParameter("client"));
    207207        if (request.getParameterValue(SAVE_AS) == null)
     
    218218        else
    219219        {
     220          if (!pathCanBeUsed((String)request.getParameterValue(ri.getParameter(SAVE_AS).getName()),
     221              (Boolean)request.getParameterValue(ri.getParameter(OVERWRITE).getName())))
     222          {
     223            response.setError("File exists: " + (String)request.getParameterValue(ri.getParameter(SAVE_AS).getName()), null);
     224            return;
     225          }
    220226          storeValue(job, request, ri.getParameter(SAVE_AS));
    221227          storeValue(job, request, ri.getParameter(OVERWRITE));
  • trunk/src/plugins/core/net/sf/basedb/plugins/PlateMappingExporter.java

    r2942 r3011  
    216216        else
    217217        {
     218          if (!pathCanBeUsed((String)request.getParameterValue(ri.getParameter(SAVE_AS).getName()),
     219              (Boolean)request.getParameterValue(ri.getParameter(OVERWRITE).getName())))
     220          {
     221            response.setError("File exists: " + (String)request.getParameterValue(ri.getParameter(SAVE_AS).getName()), null);
     222            return;
     223          }
    218224          storeValue(job, request, ri.getParameter(SAVE_AS));
    219225          storeValue(job, request, ri.getParameter(OVERWRITE));
  • trunk/src/plugins/core/net/sf/basedb/plugins/PluginConfigurationExporter.java

    r2992 r3011  
    176176        else
    177177        {
     178          if (!pathCanBeUsed((String)request.getParameterValue(ri.getParameter(SAVE_AS).getName()),
     179              (Boolean)request.getParameterValue(ri.getParameter(OVERWRITE).getName())))
     180          {
     181            response.setError("File exists: " + (String)request.getParameterValue(ri.getParameter(SAVE_AS).getName()), null);
     182            return;
     183          }
    178184          storeValue(job, request, ri.getParameter(SAVE_AS));
    179185          storeValue(job, request, ri.getParameter(OVERWRITE));
Note: See TracChangeset for help on using the changeset viewer.