Project

General

Profile

Feature #6497

add equivalent support for the -T command line option

Added by Greg Shah almost 2 years ago. Updated 5 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Theodoros Theodorou
Target version:
-
Start date:
Due date:
% Done:

100%

billable:
No
vendor_id:
GCD
version:

Screenshot 2023-07-21 000800.png - temp-directory error (9.53 KB) Theodoros Theodorou, 07/20/2023 05:12 PM

History

#2 Updated by Greg Shah almost 2 years ago

The -T <temp_dir> sets the temp directory for a 4GL client. We should implement it as a bootstrap config override.

#3 Updated by Greg Shah about 1 year ago

  • Assignee set to Theodoros Theodorou

#4 Updated by Theodoros Theodorou about 1 year ago

  • Status changed from New to WIP

#5 Updated by Theodoros Theodorou about 1 year ago

I found this documentation page: https://proj.goldencode.com/projects/p2j/wiki/Bootstrap_Configuration

As I understand, I should add the new parameter in client.xml under the following path:

<?xml version="1.0"?>
<node type="client">
   <client>
      <cmd-line-option temp-directory="/tmp/"/>
   </client>
</node>

Then I found the method ClientCore.processClientParams() which I suppose it can be used for reading the client parameters, e.g.:

cp.tempDirectory = config.getString("client", "cmd-line-option", "temp-directory", null);

Is this correct so far?

I compiled message session:temp-directory. and I got message(EnvironmentOps.getTempDirectory()); in java. Should this be under EnvironmentOps.java or should I move it under a class related to session like SessionUtils.java?

In SessionUtils.java there is an anonymous class which overrides rotected WorkArea initialValue(). As I can see, there are some client parameters there.

The current implmenetation leads to a client-side call to Utils.getOrCreateDefaultFwdTemporaryDirectory().
Another option is to add a parameter to Utils.Workarea or modify the existing private String defaultFwdTempFolder = "fwd" + new Random().nextLong(); variable.

Which option should I take?

#6 Updated by Constantin Asofiei about 1 year ago

There are some issues here. The -T option in FWD must specify the root folder where client-specific temp folders are created. We can't use the same folder for all clients.

When -T is set, this Utils.getOrCreateTemporaryDirectory code:

      // setting up temporary files upload directory
      String tmpDir;
      try
      {
         Path tmpFile = Files.createTempFile("tmp-file", ".tmp");
         String absolutePath = tmpFile.toAbsolutePath().toString();
         tmpDir = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator) + 1);
         Files.delete(tmpFile);
      }
      catch (IOException e)
      {
         // for the case the regular way above does not work
         tmpDir = System.getProperty("user.home");
      }

needs to use that folder as the temp folder. Also, when -T is set, there must be a check if this folder really exists - if it doesn't exist, log a message and default to the OS temp folder as computed in the code above.

#7 Updated by Constantin Asofiei about 1 year ago

Regarding where to save this -T option - Utils$WorkArea.explicitTempFolder should be OK (a better name can be used).

#8 Updated by Constantin Asofiei about 1 year ago

Constantin Asofiei wrote:

Also, when -T is set, there must be a check if this folder really exists - if it doesn't exist, log a message and default to the OS temp folder as computed in the code above.

Greg, another idea: we automatically create this root folder if it doesn't exist. Also, permissions should be checked (i.e. create a file in this folder).

#9 Updated by Greg Shah about 1 year ago

Greg, another idea: we automatically create this root folder if it doesn't exist. Also, permissions should be checked (i.e. create a file in this folder).

Yes, let's do both of these things. If the 4GL detects these cases and generates any error(s), we should do the same.

#10 Updated by Theodoros Theodorou about 1 year ago

String tmpDir;
try
{
 Path tmpFile = Files.createTempFile("tmp-file", ".tmp");
 String absolutePath = tmpFile.toAbsolutePath().toString();
 tmpDir = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator) + 1);
 Files.delete(tmpFile);
}
catch (IOException e)
{
   // for the case the regular way above does not work
tmpDir = System.getProperty("user.home");
}

As I understand, this code actually exists just to get the temporary directory of the OS. For the linux it is the /tmp. This creates a temp file to extract the information from its full path and then deletes it.

I believe this can be replaced with
String tmpDir = doPrivileged(new GetPropertyAction("java.io.tmpdir")); or
String tmpDir = System.getProperty("java.io.tmpdir");.
Should I proceed with the replacement?

#11 Updated by Theodoros Theodorou about 1 year ago

Also, when -T is set, there must be a check if this folder really exists - if it doesn't exist, log a message and default to the OS temp folder as computed in the code above.

I created this program to examine the behaviour of -T.

OUTPUT TO test.txt.
message session:temp-directory.
message 'test1234'.
OUTPUT CLOSE.

I executed it using the command line prowin32 -p o.p -T D:\tt1\test\fwd. If the directory does not exist, I get the following error: Unable to open or create: D:\tt1\test\fwd\lbia06628, error 2. (354)

The suffix number in lbia06628 looks like a random 5-digit number. Should we popup a similar error message or just log a message into the log file?

#12 Updated by Theodoros Theodorou about 1 year ago

  • Status changed from WIP to Review
  • % Done changed from 0 to 100

I implemented the following functionality:

If a temp directory is is explicitly provided, then I check if it is indeed a directory which already exists and we have write access. If yes then I use it. If not then I log a warning and the old algorithm is used.

The branch 6497a is ready for review.

#13 Updated by Greg Shah about 1 year ago

Does it match the 4GL behavior?

Constantin: Please review.

#14 Updated by Theodoros Theodorou about 1 year ago

Yes, it matches the 4GL behavior

#15 Updated by Theodoros Theodorou about 1 year ago

Kind reminder for a review

#16 Updated by Constantin Asofiei about 1 year ago

Theodoros, this is the review for 6497a/14500:
  • please add history entries and javadoc for all new methods or parameters added to new methods.
  • although -T specifies a temporary folder for a OE client, in FWD terms all OE clients are on the same machine - although they can share the -T folder, they can't share the physical folder! You need to create a sub-folder in the '-T' folder, with some random value, and assign it to the temp-dir for a FWD client - see how defaultFwdTempFolder behaves. We can't break this and allow FWD clients to share the same physical temp-folder, each FWD client needs to have its own temp folder in the 'root temp-folder specified via -T'.

#17 Updated by Constantin Asofiei about 1 year ago

In other words, defaultFwdTempFolder needs to be used in both cases, implicit temp folder and explicit '-T' folder; you just create defaultFwdTempFolder the sub-folder in each case, after you calculate the root temp folder.

#18 Updated by Theodoros Theodorou about 1 year ago

Please review again (6497a/14501)

#19 Updated by Constantin Asofiei about 1 year ago

Review for 6497a/14501:
  • ClientCore, ClientParameters, StandardServer - please add history entries
  • Utils.getTmpDir - please add some javadoc, there are only params there now.
  • Utils.tryToSetTempDir - please improve the warning messages to say something like "Trying to set temp folder to " + folderName + " failed - the path is not a directory"; the point is to indicate this is related to setting the temp folder.

Otherwise, the logic is OK now.

#20 Updated by Theodoros Theodorou about 1 year ago

Please review (6497a/14502)

#21 Updated by Constantin Asofiei about 1 year ago

Theodoros Theodorou wrote:

Please review (6497a/14502)

Looks good, thanks.

#22 Updated by Theodoros Theodorou about 1 year ago

The branch 6497a has been rebased to trunk 14519. The new rev no is 14524.

#23 Updated by Theodoros Theodorou about 1 year ago

The branch 6497a has been rebased to trunk 14521. The new rev no is 14526.

Please review it and let me know if I can merge it.

#24 Updated by Greg Shah about 1 year ago

Please rebase from the latest trunk and we will review this.

#25 Updated by Theodoros Theodorou about 1 year ago

The branch 6497a has been rebased to trunk 14553. The new rev no is 14558.

#26 Updated by Greg Shah 11 months ago

Please merge 6497a into 4938a. Add/rework support for -T to the STARTUP-PARAMETERS.

#28 Updated by Greg Shah 10 months ago

The code review for these changes (in branch 4938b) can be seen in #4938-225.

#29 Updated by Theodoros Theodorou 10 months ago

OE throws an error if the temporary directory provided as a startup parameter is problematic (e.g. permission issue or the directory does not exist or the path is a file) and the application does not start.

I want to replicate this behaviour in FWD but when I try to add ErrorManager.recordOrThrowError(...) it throws an exception.

Please add <cmd-line-option temporary-directory="random_path"/> in client.xml and check the line 3872 (branch 4938b). It throws an exception instead of showing the error. How can I make it work?

#30 Updated by Greg Shah 10 months ago

OE throws an error if

What do you mean by this? Show some 4GL code and output to demonstrate.

It throws an exception instead of showing the error. How can I make it work?

Throwing the ErrorConditionException is how we cause the 4GL ERROR condition to be raised. The 4GL code will respond to that in different ways depending mostly only the NO-ERROR flag. In FWD, NO-ERROR converts to "silent mode" where we record the error details into the ERROR-STATUS handle but we don't change the control flow.

What do you mean by "showing the error"? A 4GL example with output would help.

#31 Updated by Constantin Asofiei 10 months ago

Theodoros Theodorou wrote:

OE throws an error if the temporary directory provided as a startup parameter is problematic (e.g. permission issue or the directory does not exist or the path is a file) and the application does not start.

I want to replicate this behaviour in FWD but when I try to add ErrorManager.recordOrThrowError(...) it throws an exception.

You are calling Utils.setTemporaryDirectory(sp.getTemporaryDirectory());, which uses ErrorManager.recordOrThrowError(...) (and System.exit() ? why is this needed?) from ClientCore.initialize - this is before the FWD client gets fully initialized to be able to properly display any error messages.

#32 Updated by Theodoros Theodorou 10 months ago

Greg Shah wrote:

What do you mean by this? Show some 4GL code and output to demonstrate.
...
What do you mean by "showing the error"? A 4GL example with output would help.

To set up the temporary directory you need to run something like prowin -T random_path test.p. The code session:temp-directory = 'random_path' is not valid because session:temp-directory is read-only. This means you can define the temp-directory only at startup.

Constantin Asofiei wrote:

(and System.exit() ? why is this needed?)

If the path provided is problematic, the application will not start at all. That is why I added System.exit().

#33 Updated by Greg Shah 9 months ago

  • Status changed from Review to Closed

The changes for this task were written in branch 4938b and were merged into trunk as revision 14688.

#34 Updated by Greg Shah 5 months ago

6497a was dead-archived.

Also available in: Atom PDF