manywaypark's Blog
개발, 검색, 함수

문제:
Qt의 QFile::copy()는 Windows와 Symbian에서만 native copy를 사용해 구현되어있다(2011-07-20 기준).
http://bugreports.qt.nokia.com/browse/QTBUG-10369
http://bugreports.qt.nokia.com/browse/QTBUG-10337
따라서 다른 platform에서 copy()를 사용하면 복사된 파일이 copy() 수행 시점의 timestamp를 가지게 된다.

해결:
지금 내 경우에는 생성시간의 유지가 중요한 상황이므로 다음과 같이 간단하게 회피하는 QFileFixed class를 만들어서 해결했다.

// file: QFileFixed.h

//! \author manywaypark at gmail.com http://manywaypark.tistory.com
 

class QFileFixed : public QFile

{

public:

    QFileFixed(const QString &name);

#if !(defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN))

    bool copy(const QString &newName);

    static bool copy(const QString &fileName, const QString &newName);

private:

    static void copyFileTime(const QFileInfo &srcInfo, const QString &dstPath);

#endif

};


// file: QFileFixed.cpp

//! \author manywaypark at gmail.com http://manywaypark.tistory.com


#if !(defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN))

#include <sys/time.h>

#endif


QFileFixed::QFileFixed(const QString &name)

    : QFile(name)

{}


#if !(defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN))

bool QFileFixed::copy(const QString &newName){

    bool r(QFile::copy(newName));

    if (r) copyFileTime(QFileInfo(*this), newName);

    return r;

}


bool QFileFixed::copy(const QString &fileName, const QString &newName)

{

    bool r(QFile::copy(fileName, newName));

    if (r) copyFileTime(QFileInfo(fileName), newName);

    return r;

}


void QFileFixed::copyFileTime(const QFileInfo &srcInfo, const QString &dstPath)

{

    QDateTime access(srcInfo.lastRead());

    QDateTime created(srcInfo.created()); /* created == modification?? */

    struct timeval time[2];

    time[0].tv_sec = access.toTime_t();

    time[0].tv_usec = access.time().msec() * 1000; /* millisecond to microsecond */

    time[1].tv_sec = created.toTime_t();

    time[1].tv_usec = created.time().msec() * 1000; /* millisecond to microsecond */

    int r = utimes(dstPath.toAscii().constData(), time);


    Q_ASSERT(r == 0);

}

#endif // !(defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)


Windows와 Mac OSX에서 테스트되었고, 내가 필요한 파일 생성 시간 유지는 잘 되는 것을 확인했다.

happy hackin'

[BR] EUnit Bug Report

함수형 언어/Erlang 2008. 12. 24. 18:25 by manywaypark
맨 마지막 테스트 함수의 테스트 준비단계가 2번 실행되는 버그가 있는 것같다.
나의 test case가 성공할 때도 있고 실패할 때도 있는 이상한 상태가 되어서 내 잘못인 줄 알고 개발중인 모듈의 여기저기를 손댔다가 갑자기 느끼는 바가 있어 EUnit을 테스트하는 간단한 코드를 만들었다.

일단 공식적으로 버그 리포트는 했고,
참고를 위해 글을 남긴다.

last_test_() ->
do_some_prep(), % 요놈이 매번 두번씩 불린단 말씀.
... do some tests ...
do_some_prep()가 두번 불려지면 당혹스런(?) 테스트 실패가 나올 수 있다. disk i/o나 DB operation 처럼 side effect가 있는 경우에 특히 테스트가 통과될 때도 있고 안될때도 있는 불안정한 상태가 될 수 있다.

happy hackin'

ps. 글을 쓰고 좀더 만져 보니 조금 더 복잡하다. EUnit 사이트에 올린 케이스들 말고 테스트 케이스를 다음과 같이 하면...

twice_case1_test_() ->
    io:format("c1: prep one~n"),
    ?_assert(1 + 1 =:= 2).

twice_case2_test_() ->
    io:format("c2: prep one~n"),
    ?_assert(1 + 1 =:= 2).

twice_case3_test_() ->
    io:format("c3: prep one~n"),
    ?_assert(1 + 1 =:= 2).

결과:
(emacs@desktop)14> eunit_twice_case:test().
c3: prep one
c2: prep one
c3: prep one
c2: prep one
c1: prep one
  All 3 tests successful.
ok
마지막에 있는 두개가 두번씩 불린다.

2008-12-31 "by design" 이라는군요 Orz. side effect가 있는 함수는 준비단계에서 부르면 절대 안되겠습니다.
해당 version: R12B-3

xmerl을 사용하여 다량의 xml 파일들을 파싱하는 도중에 특정 파일에서 CPU/메모리사용량이 치솟고 다음과 같은 에러메시지와 함께 erlang이 죽어버렸다.

eheap_alloc: Cannot allocate xxxxx bytes of memory (of type "heap").

특정 파일 하나에서만 이 현상이 생겼는데, 파일을 열어보니 복잡한 테이블과, entity들을 많이 사용한 xml이었다. 조금 복잡하긴 했지만 정상적인 xml이었다.

검색한 결과 xmerl_scan의 버그임이 밝혀졌다.
(R12B-4 에서는 패치된 버전이 포함될 것이라고 한다).

링크에 나와있는대로 한줄만 고쳐주면 에러없이 잘 동작한다.



happy hackin'
1 
분류 전체보기 (306)
잡담 (20)
함수형 언어 (65)
emacs (16)
java (18)
tips & tricks (154)
사랑 (1)
가사 (0)
독서 (4)
mobile (6)
비함수형 언어 (2)

공지사항

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

04-25 06:24