|
21 | 21 | # KIND, either express or implied. See the License for the |
22 | 22 | # specific language governing permissions and limitations |
23 | 23 | # under the License. |
| 24 | +import logging |
24 | 25 | import os |
25 | 26 | import sys |
26 | | -from osbenchmark.utils.io import ensure_dir |
| 27 | +from osbenchmark.utils.io import ensure_dir, ensure_symlink |
27 | 28 |
|
28 | 29 | def benchmark_confdir(): |
| 30 | + logger = logging.getLogger("opensearch_benchmark") |
29 | 31 | default_home = os.path.expanduser("~") |
30 | 32 | old_path = os.path.join(default_home, ".benchmark") |
31 | 33 | new_path = os.path.join(default_home, ".osb") |
32 | 34 |
|
33 | | - # ensure both directories exist |
34 | | - ensure_dir(old_path) |
35 | | - ensure_dir(new_path) |
| 35 | + try: |
| 36 | + # Ensure .benchmark directory exists |
| 37 | + ensure_dir(old_path) |
| 38 | + logger.info(f"Ensured directory exists: {old_path}") |
36 | 39 |
|
37 | | - # Create symlink from .osb to .benchmark if it doesn't exist |
38 | | - if not os.path.islink(new_path): |
39 | | - try: |
40 | | - os.symlink(old_path, new_path, target_is_directory=True) |
41 | | - except OSError as e: |
42 | | - error_message = ( |
43 | | - f"OSError: Failed to create symlink from {new_path} to {old_path}\n" |
44 | | - f"Error type: {type(e).__name__}\n" |
45 | | - f"Error message: {str(e)}\n" |
46 | | - ) |
47 | | - print(error_message, file=sys.stderr) |
| 40 | + # Ensure symlink from .osb to .benchmark |
| 41 | + ensure_symlink(old_path, new_path) |
48 | 42 |
|
49 | | - return os.path.join(os.getenv("BENCHMARK_HOME", default_home), ".osb") |
| 43 | + final_path = os.path.join(os.getenv("BENCHMARK_HOME", default_home), ".osb") |
50 | 44 |
|
| 45 | + return final_path |
| 46 | + |
| 47 | + except Exception as e: |
| 48 | + error_message = ( |
| 49 | + f"Error in benchmark_confdir:\n" |
| 50 | + f"Error type: {type(e).__name__}\n" |
| 51 | + f"Error message: {str(e)}\n" |
| 52 | + f"Current user: {os.getlogin()}\n" |
| 53 | + f"Current working directory: {os.getcwd()}\n" |
| 54 | + f"Python version: {sys.version}\n" |
| 55 | + f"Operating system: {sys.platform}\n" |
| 56 | + f"Permissions of {old_path}: {oct(os.stat(old_path).st_mode) if os.path.exists(old_path) else 'N/A'}\n" |
| 57 | + f"Permissions of parent of {new_path}: {oct(os.stat(os.path.dirname(new_path)).st_mode)}" |
| 58 | + ) |
| 59 | + print(error_message) |
| 60 | + raise |
51 | 61 |
|
52 | 62 | def benchmark_root(): |
53 | 63 | return os.path.dirname(os.path.realpath(__file__)) |
|
0 commit comments