Skip to content

umlaut in directory path throws error #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
khainke opened this issue Apr 6, 2022 · 5 comments
Closed

umlaut in directory path throws error #406

khainke opened this issue Apr 6, 2022 · 5 comments
Labels
bug Something isn't working
Milestone

Comments

@khainke
Copy link

khainke commented Apr 6, 2022

using a path with umlauts (ä,ü,ö) for the directory argument of openStore throws an error. It attempts to create a different directory / umlauts are replaced with other characters.

Why is this relevant?

The application support directory includes the user name. The user name in Windows can include umlauts. The application support directory is the prefered location for such files, i.e. databases like objectbox. Other directories often include the user directory as a part. Therefore, this issue is quite a severe one for Windows support.

Basic info (please complete the following information):

  • ObjectBox version: 1.4.1
  • Flutter/Dart SDK:
Flutter 2.10.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision db747aa133 (8 weeks ago) • 2022-02-09 13:57:35 -0600
Engine • revision ab46186b24
Tools • Dart 2.16.1 • DevTools 2.9.2
  • Null-safety enabled: yes
  • Reproducibility: always
  • OS: Windows 10

Steps to reproduce

final sep = Platform.pathSeparator;
final appSupportDir = await getApplicationSupportDirectory();
final dirPath = '${appSupportDir.absolute.path}${sep}testäüö${sep}objectbox';
await Directory(dirPath).create(recursive: true);
_store = await openStore(
  directory: dirPath,
);

Expected behavior

  • if not already existent, create the directory .../testäüö/objectbox
  • create store / save store to this directory

Current behavior

001-11:29:38.8023 [ERROR] Storage error "No such file or directory" (code 2)
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: ObjectBoxException: failed to create store: 10199 Could not prepare directory: C:\Users\user\AppData\Roaming\com.example\objectbox_test\testäüö\objectbox (2)
#0      ObjectBoxNativeError.throwMapped (package:objectbox/src/native/bindings/helpers.dart:78:9)
#1      throwLatestNativeError (package:objectbox/src/native/bindings/helpers.dart:50:48)
#2      checkObxPtr (package:objectbox/src/native/bindings/helpers.dart:32:5)
#3      Store._checkStorePointer (package:objectbox/src/native/store.dart:285:7)
#4      new Store (package:objectbox/src/native/store.dart:147:7)
#5      openStore (package:objectbox_test/objectbox.g.dart:95:5)
#6      ObjectBoxService.init (package:objectbox_test/objectbox/objectbox_service.dart:26:20)
<asynchronous suspension>
#7      main (package:objectbox_test/main.dart:8:3)
<asynchronous suspension>

Code

main.dart

import 'package:flutter/material.dart';
import 'objectbox/objectbox_service.dart';

import 'main_page/main_page.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await ObjectBoxService.instance.init();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'ObjectBox Test',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MainPage(),
    );
  }
}
 

objectbox/objectbox_service.dart

import 'dart:io';

import '../objectbox.g.dart';
import 'package:path_provider/path_provider.dart';

class ObjectBoxService {
  ObjectBoxService._internal();

  static final ObjectBoxService _instance = ObjectBoxService._internal();

  factory ObjectBoxService() => ObjectBoxService.instance;

  static ObjectBoxService get instance => _instance;

  late Store _store;

  Store get store => _store;

  /// Initializes this service.
  Future<void> init() async {
    final sep = Platform.pathSeparator;
    final appSupportDir = await getApplicationSupportDirectory();
    final dirPath = '${appSupportDir.absolute.path}${sep}testäüö${sep}objectbox';
    await Directory(dirPath).create(recursive: true);
    _store = await openStore(
      directory: dirPath,
    );
  }
}
@khainke khainke added the bug Something isn't working label Apr 6, 2022
@Buggaboo
Copy link
Contributor

Buggaboo commented Apr 7, 2022

Hi,

This path canonicalization function could be useful to you. This is a windows specific bug.

@khainke
Copy link
Author

khainke commented Apr 7, 2022

This is already used internally by objectbox, see

path.context.canonicalize(_safeDirectoryPath(directory)) {

directoryPath = _safeDirectoryPath(directory),
_absoluteDirectoryPath = path.context.canonicalize(_safeDirectoryPath(directory)

We believe, that the problem lies within the objectbox-c library. The directory path is encoded in utf8 to transfer it to the ffi libraries and there then decoded again. Somewhere along this path, we believe there is a bug, that prevents umlauts from being interpreted correctly, when setting up the store.

@greenrobot-team
Copy link
Member

greenrobot-team commented Apr 11, 2022

Thank you for the stellar bug report! I could reproduce this on Windows 10 as well.

Side note: the canonicalize above is only used on the Dart side to track open directories. It's not used on the path passed to the C library.

@greenrobot
Copy link
Member

This is fixed internally; after a review, we hope to release a new version beginning next week.

@greenrobot-team greenrobot-team added this to the 1.4.2 milestone Apr 25, 2022
@greenrobot-team
Copy link
Member

The fix is now available as part of the 1.5.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants